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 ProductLibraryRepositoriesTypeEnum {
    HOSTED("hosted", "托管仓库"),
    GROUP("group", "虚拟仓库");

    private final String key;
    private final String name;

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

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

    public static ProductLibraryRepositoriesTypeEnum getByKey(String key) {
        for (ProductLibraryRepositoriesTypeEnum typeEnum : ProductLibraryRepositoriesTypeEnum.values()) {
            if (typeEnum.key.equals(key)) {
                return typeEnum;
            }
        }
        throw new ServiceException("该制品库类型不存在(制品库类型[%s])", key);
    }
}
