package com.microservices.pms.productLibrary.domain;

import com.microservices.common.core.exception.ServiceException;
import com.microservices.pms.productLibrary.domain.vo.CommonTypeVo;
import io.swagger.annotations.ApiModel;
import lombok.Getter;

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

/**
 * @author OTTO
 */
@Getter
@ApiModel("版本策略")
public enum VersionPolicyEnum {
    RELEASE("RELEASE", "发布版本"),
    SNAPSHOT("SNAPSHOT", "快照版本"),
    MIXED("MIXED", "混合版本");

    private final String key;
    private final String name;

    VersionPolicyEnum(String key, String name) {
        this.key = key;
        this.name = name;
    }

    public static List<CommonTypeVo> getAllToList() {
        List<CommonTypeVo> list = new ArrayList<>();
        for (VersionPolicyEnum e : VersionPolicyEnum.values()) {
            list.add(new CommonTypeVo(e.key, e.name));
        }
        return list;
    }

    public static VersionPolicyEnum getByKey(String key) {
        for (VersionPolicyEnum typeEnum : VersionPolicyEnum.values()) {
            if (typeEnum.key.equals(key)) {
                return typeEnum;
            }
        }
        throw new ServiceException("该版本策略不存在(版本策略[%s])", key);
    }

}
