package com.qmth.sop.common.enums;

import java.util.Objects;

/**
 * @Description: 流程审批操作 enum
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2021/8/2
 */
public enum FlowApproveOperationEnum {

    START("提交", "submit"),

    DRAFT("草稿", "draft"),

    APPROVE("审批", "approve"),

    REJECT("驳回", "reject"),

    END("终止", "end"),

    CANCEL("撤销", "cancel"),

    EXCHANGE("转他人审批", "exchange"),

    FINISH("结束", "finish");

    private String title;

    private String id;

    private FlowApproveOperationEnum(String title, String id) {
        this.title = title;
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    /**
     * 状态转换 toName
     *
     * @param title
     * @return
     */
    public static String convertToName(String title) {
        for (FlowApproveOperationEnum e : FlowApproveOperationEnum.values()) {
            if (Objects.equals(title, e.getTitle())) {
                return e.name();
            }
        }
        return null;
    }

    /**
     * 状态转换 toEnum
     *
     * @param name
     * @return
     */
    public static FlowApproveOperationEnum convertToEnum(String name) {
        for (FlowApproveOperationEnum e : FlowApproveOperationEnum.values()) {
            if (Objects.equals(name, e.name())) {
                return e;
            }
        }
        return null;
    }
}
