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

import cn.reghao.bnt.common.msg.constant.PackType;
import cn.reghao.bnt.web.devops.build.model.po.PackerConfig;
import org.hibernate.validator.spi.group.DefaultGroupSequenceProvider;

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

/**
 * @author reghao
 * @date 2023-03-13 17:49:57
 */
public class PackerConfigGroupSequenceProvider implements DefaultGroupSequenceProvider<PackerConfig> {
    @Override
    public List<Class<?>> getValidationGroups(PackerConfig packerConfig) {
        List<Class<?>> defaultGroupSequence = new ArrayList<>();
        defaultGroupSequence.add(PackerConfig.class);

        if (packerConfig != null) {
            String packType = packerConfig.getType();
            if (packType.equals(PackType.docker.getName())) {
                defaultGroupSequence.add(PackerConfig.DockerPacker.class);
            } else if (packType.equals(PackType.zip.getName())) {
                defaultGroupSequence.add(PackerConfig.ZipPacker.class);
            }
        }

        return defaultGroupSequence;
    }
}
