package cn.axzo.workflow.common.enums;

import java.util.Arrays;

public enum BpmnProcessInstanceResultEnum {
    PROCESSING("PROCESSING", "审批中"),
    APPROVED("APPROVED", "已通过"),
    REJECTED("REJECTED", "已驳回"),
    CANCELLED("CANCELLED", "已撤回"),
    ABORTED("ABORTED", "已中止"),
    TRANSFER("TRANSFER", "已转交"),
    COUNTERSIGN("COUNTERSIGN", "已加签"),
    COMMENTED("COMMENTED", "已评论"),
    DELETED("DELETED", "已删除"),
    ;
    /**
     * 结果
     */
    private final String status;
    /**
     * 描述
     */
    private final String desc;

    BpmnProcessInstanceResultEnum(String status, String desc) {
        this.status = status;
        this.desc = desc;
    }

    public String getStatus() {
        return status;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 判断该结果是否已经处于 End 最终结果
     * <p>
     * 主要用于一些结果更新的逻辑，如果已经是最终结果，就不再进行更新
     *
     * @param result 结果
     * @return 是否
     */
    public static boolean isEndResult(Integer result) {
        return Arrays.asList(PROCESSING.getStatus(), APPROVED.getStatus(), REJECTED.getStatus(),
                CANCELLED.getStatus()).contains(result);
    }

    public static BpmnProcessInstanceResultEnum valueOfStatus(String status) {
        return Arrays.stream(values()).filter(it -> it.getStatus().equals(status)).findFirst()
                .orElse(DELETED);
    }

    public static BpmnProcessInstanceResultEnum valueOfDesc(String desc) {
        return Arrays.stream(values()).filter(it -> it.getDesc().equals(desc)).findFirst()
                .orElse(DELETED);
    }
}
