package cn.axzo.msg.center.service.enums;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Optional;

/**
 * @author cold_blade
 * @version 1.0
 * @description 业务终态的状态枚举，包含审批流的相关状态
 * @date 2023/11/7
 */
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum BizFinalStateEnum implements CodeDefinition<String> {

    /**
     * 已处理
     */
    COMPLETED("", "", "https://static.axzo.cn/fe-static/uni-icon/public/seal-1%23_%241699341908382.png"),
    /**
     * 已撤销
     */
    RETRACT("BPMN_REVOCATION", "已撤销", "https://static.axzo.cn/fe-static/uni-icon/native/%E5%8E%9F%E7%A8%BF%23_%241711338477975.png"),
    /**
     * 已通过
     */
    PASSED("BPMN_APPROVE", "已同意", "https://static.axzo.cn/fe-static/uni-icon/public/seal-4%23_%241699341908374.png"),
    /**
     * 已拒绝
     */
    REJECTED("BPMN_REJECT", "已驳回", "https://static.axzo.cn/fe-static/uni-icon/public/seal-2%23_%241699341908381.png"),
    /**
     * 已终止
     */
    ABORTED("", "", "https://axzo-public.oss-cn-chengdu.aliyuncs.com/%E5%8D%B0%E7%AB%A0-%E8%AF%A6%E6%83%85end.png");

    private final String buttonCode;
    private final String actionPerformedName;
    private final String icon;

    @Override
    public String getCode() {
        return name();
    }

    public static Optional<BizFinalStateEnum> findButtonClickedState(String buttonCode) {
        for (BizFinalStateEnum value : values()) {
            if (value.buttonCode.equals(buttonCode))
                return Optional.of(value);
        }
        return Optional.empty();
    }

    public boolean isButtonPerformActionAvailable() {
        return StringUtils.isNotBlank(actionPerformedName);
    }
}