package com.ruoyi.project.business.enums;

import com.ruoyi.common.exception.ServiceErrorException;
import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum AuditStatusEnum {

    /**
     * 草稿
     */
    DRAFT(0, "草稿"),
    WAITING_UPLOAD(10, "待上传"),
    REJECT(30, "已驳回"),
    ROLLBACK(40, "已撤回"),
    INIT(100, "工作流初始化"),
    TECH_REVIEW_ELECTRIC(101, "技术评审(电气)"),
    TECH_REVIEW_MACHINE(105, "技术评审(机械)"),
    BUYER_INQUIRY(102, "采购询价"),
    TREASURE_INQUIRY(103, "财务询价"),
    SALES_CONFIRM(104, "销售确认"),
    BARGAIN_APPROVAL1(111, "议价审批(销售)"),
    BARGAIN_APPROVAL2(112, "议价审批(区总)"),
    BARGAIN_APPROVAL3(113, "议价审批(销售VP)"),
    BARGAIN_APPROVAL4(114, "议价审批(总经理)"),
    BARGAIN_APPROVAL5(115, "议价审批(财务)"),
    PASS(200, "已通过");

    private Integer value;

    private String desc;

    public static AuditStatusEnum from(Integer value) {
        for (AuditStatusEnum auditFlowEnum : values()) {
            if (auditFlowEnum.getValue().equals(value)) {
                return auditFlowEnum;
            }
        }
        throw new ServiceErrorException("非法的审批状态");
    }

    public static AuditStatusEnum fromDesc(String value) {
        for (AuditStatusEnum auditFlowEnum : values()) {
            if (auditFlowEnum.getDesc().equals(value)) {
                return auditFlowEnum;
            }
        }
        throw new ServiceErrorException("非法的审批状态");
    }

    public static AuditStatusEnum fromByCode(String value) {
        for (AuditStatusEnum auditFlowEnum : values()) {
            if (auditFlowEnum.getValue().toString().equals(value)) {
                return auditFlowEnum;
            }
        }
        throw new ServiceErrorException("非法的审批状态");
    }

    public static AuditStatusEnum fromDescOut(String value) {
        for (AuditStatusEnum auditFlowEnum : values()) {
            if (auditFlowEnum.getDesc().equals(value)) {
                return auditFlowEnum;
            }
        }
        return null;
    }

    public static AuditStatusEnum fromByCodeOut(String value) {
        for (AuditStatusEnum auditFlowEnum : values()) {
            if (auditFlowEnum.getValue().toString().equals(value)) {
                return auditFlowEnum;
            }
        }
        return null;
    }

    /**
     * 100~200分配给扩展的审核节点
     *
     * @param value
     * @return
     */
    public static boolean isAuditing(Integer value) {
        return value >= 100 && value < 200;
    }
}
