package com.ningdatech.pmapi.todocenter.enumeration;

import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * 待办中心-流程状态枚举
 *
 * @author CMM
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "ProcessStatusEnum", description = "流程状态-枚举")
public enum ProcessStatusEnum {
    /**
     * 审核中
     */

    UNDER_REVIEW(1, "审核中"),

    /**
     * 被退回
     */
    BE_BACKED(2, "被退回"),

    /**
     * 被驳回
     */
    BE_REJECTED(3, "被驳回"),

    /**
     * 审核通过
     */
    APPROVED(4, "审核通过"),
    /**
     * 被撤回
     */
    WITHDRAW(5, "被撤回");


    private Integer code;
    private String desc;

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static String getDescByCode(Integer code) {
        if (Objects.isNull(code)) {
            return StringUtils.EMPTY;
        }
        for (ProcessStatusEnum t : ProcessStatusEnum.values()) {
            if (code.equals(t.getCode())) {
                return t.desc;
            }
        }
        return StringUtils.EMPTY;
    }

    public static Integer getCodeByDesc(String desc) {
        if (Objects.isNull(desc)) {
            return null;
        }
        for (ProcessStatusEnum t : ProcessStatusEnum.values()) {
            if (desc.equals(t.getDesc())) {
                return t.code;
            }
        }
        return null;
    }

    public static ProcessStatusEnum getEnumByValue(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        for (ProcessStatusEnum t : ProcessStatusEnum.values()) {
            if (code.equals(t.getCode())) {
                return t;
            }
        }
        return null;
    }

    public boolean eq(String val) {
        return this.name().equals(val);
    }
}
