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 LayoutPolicyEnum {
    STRICT("STRICT", "严格的"),
    PERMISSIVE("PERMISSIVE", "许可的");

    private final String key;
    private final String name;

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

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


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