package cn.palmte.work.config.activiti;


import cn.palmte.work.exception.ResponseException;
import lombok.Getter;

/**
 * 流程定义key枚举
 */
@Getter
public enum ActProcessKeyEnum {
    ESTIMATE("estimate", "概算审批流程"),
    BUDGET("budget", "预算审批流程"),
    SETTLE("settle", "结算审批流程"),
    FINAL("final", "决算审批流程"),
    SALE_CONTRACT("saleContract", "销售合同审批流程"),
    BUSINESS_PURCHASE("businessPurchase", "业务采购审批流程");


    private String key;
    private String name;

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

    public static ActProcessKeyEnum ofKey(String key) {
        if (ESTIMATE.getKey().equals(key)) {
            return ESTIMATE;
        } else if (BUDGET.getKey().equals(key)) {
            return BUDGET;
        } else if (SETTLE.getKey().equals(key)) {
            return SETTLE;
        } else if (FINAL.getKey().equals(key)) {
            return FINAL;
        } else if (SALE_CONTRACT.getKey().equals(key)) {
            return SALE_CONTRACT;
        } else if (BUSINESS_PURCHASE.getKey().equals(key)) {
            return BUSINESS_PURCHASE;
        } else {
            throw new ResponseException("不支持的流程key【" + key + "】");
        }
    }

    public static ActProcessKeyEnum ofProcDefId(String proDefId) {
        if (proDefId.startsWith(ESTIMATE.getKey())) {
            return ESTIMATE;
        } else if (proDefId.startsWith(BUDGET.getKey())) {
            return BUDGET;
        } else if (proDefId.startsWith(SETTLE.getKey())) {
            return SETTLE;
        } else if (proDefId.startsWith(FINAL.getKey())) {
            return FINAL;
        } else if (proDefId.startsWith(SALE_CONTRACT.getKey())) {
            return SALE_CONTRACT;
        } else if (proDefId.startsWith(BUSINESS_PURCHASE.getKey())) {
            return BUSINESS_PURCHASE;
        } else {
            throw new ResponseException("不支持的流程key【" + proDefId + "】");
        }
    }
}
