package com.microservices.pms.product.domain.enums;

import com.microservices.common.core.exception.ServiceException;
import com.microservices.pms.product.domain.vo.EnumCommonVo;
import lombok.Getter;

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

/**
 * @author OTTO
 */
@Getter
public enum ProductReqSpecsType {
    PERFORMANCE_REQ("performanceReq", "性能需求"),
    FUNCTIONAL_REQ("functionalReq", "功能需求");
    private final String key;
    private final String name;

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

    public static void checkKey(String key) {
        for (ProductReqSpecsType type : ProductReqSpecsType.values()) {
            if (type.getKey().equals(key)) {
                return;
            }
        }
        throw new ServiceException("错误的需求类型(需求类型[%s])", key);
    }


    public static List<EnumCommonVo> getReqSpecsTypeList() {
        List<EnumCommonVo> typeCommonVoList = new ArrayList<>();
        for (ProductReqSpecsType productReqSpecsType : ProductReqSpecsType.values()) {
            typeCommonVoList.add(new EnumCommonVo(productReqSpecsType.key, productReqSpecsType.name));
        }
        return typeCommonVoList;
    }
}
