package com.codvision.workflow.constant.enums;


import com.codvision.auth.entity.vo.SysUserVO;
import com.codvision.auth.support.UserContext;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 动态表单内置变量
 * @author hxl
 */
@Getter
@AllArgsConstructor
public enum WorkFlowFormInnerVariableEnum {

    // 操作人姓名
    OPERATOR_NAME,
    // 操作人联系电话
    OPERATOR_TEL,
    // 操作人所属组织
    OPERATOR_ORG_NAME,
    ;

    public static boolean isInner(String variable) {
        for (WorkFlowFormInnerVariableEnum value : values()) {
            if (value.name().equals(variable)) {
                return true;
            }
        }

        return false;
    }

    public static String get(String variable) {
        SysUserVO sysUserVO = UserContext.get();
        for (WorkFlowFormInnerVariableEnum value : values()) {
            if (value.name().equals(variable)) {
                switch (value) {
                    case OPERATOR_NAME:
                        return sysUserVO.getName();
                    case OPERATOR_TEL:
                        return sysUserVO.getMobile();
                    case OPERATOR_ORG_NAME:
                        return sysUserVO.getActiveOrgName();
                    default:
                }
            }
        }

        return null;
    }
}
