package cn.reghao.bnt.web.devops.build.model.provider;

import cn.reghao.bnt.web.devops.build.model.po.CompilerConfig;
import cn.reghao.bnt.web.devops.builder.model.constant.CompileType;
import org.hibernate.validator.spi.group.DefaultGroupSequenceProvider;

import java.util.ArrayList;
import java.util.List;

/**
 * @author reghao
 * @date 2023-03-10 20:43:47
 */
public class CompilerConfigGroupSequenceProvider implements DefaultGroupSequenceProvider<CompilerConfig> {
    @Override
    public List<Class<?>> getValidationGroups(CompilerConfig compilerConfig) {
        List<Class<?>> defaultGroupSequence = new ArrayList<>();
        defaultGroupSequence.add(CompilerConfig.class);

        if (compilerConfig != null) {
            String compileType = compilerConfig.getType();
            if (compileType.equals(CompileType.none.getName())) {
                defaultGroupSequence.add(CompilerConfig.NoneCompiler.class);
            } else if (compileType.equals(CompileType.shell.getName())) {
                defaultGroupSequence.add(CompilerConfig.ShellCompiler.class);
            } else if (compileType.equals(CompileType.maven.getName())) {
                defaultGroupSequence.add(CompilerConfig.MavenCompiler.class);
            }
        }

        return defaultGroupSequence;
    }
}
