package org.jeecg.common.utils;

import com.google.common.collect.Lists;
import lombok.Data;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 字典枚举
 */
@Getter
public enum DictEnum {

    /*********************** 公共模块 *************************/
    // 星期
    BASE_WEEKS_SUNDAY(DictModelConstant.MODEL_BASE, DictModelConstant.MODEL_BASE_WEEK, "1", "星期日"),
    BASE_WEEKS_MONDAY(DictModelConstant.MODEL_BASE, DictModelConstant.MODEL_BASE_WEEK, "2", "星期一"),
    BASE_WEEKS_TUESDAY(DictModelConstant.MODEL_BASE, DictModelConstant.MODEL_BASE_WEEK, "3", "星期二"),
    BASE_WEEKS_WEDNESDAY(DictModelConstant.MODEL_BASE, DictModelConstant.MODEL_BASE_WEEK, "4", "星期三"),
    BASE_WEEKS_THURSDAY(DictModelConstant.MODEL_BASE, DictModelConstant.MODEL_BASE_WEEK, "5", "星期四"),
    BASE_WEEKS_FRIDAY(DictModelConstant.MODEL_BASE, DictModelConstant.MODEL_BASE_WEEK, "6", "星期五"),
    BASE_WEEKS_SATURDAY(DictModelConstant.MODEL_BASE, DictModelConstant.MODEL_BASE_WEEK, "7", "星期六"),


    /*********************** 任务申请模块 *************************/

    // 流程状态
    APPLY_STATUS_NOT_START(DictModelConstant.MODEL_APPLY, DictModelConstant.MODEL_APPLY_STATUS, "0", "未开始"),
    APPLY_STATUS_PROCESSING(DictModelConstant.MODEL_APPLY, DictModelConstant.MODEL_APPLY_STATUS, "1", "进行中"),
    APPLY_STATUS_FINISH(DictModelConstant.MODEL_APPLY, DictModelConstant.MODEL_APPLY_STATUS, "2", "已结束"),

    //流程审批结果
    APPLY_RESULT_REFUSE(DictModelConstant.MODEL_APPLY,DictModelConstant.MODEL_APPLY_RESULT,"0","未通过"),
    APPLY_RESULT_AGREE(DictModelConstant.MODEL_APPLY,DictModelConstant.MODEL_APPLY_RESULT,"1","通过"),
    APPLY_RESULT_PROCESSING(DictModelConstant.MODEL_APPLY,DictModelConstant.MODEL_APPLY_RESULT,"2","审批中"),
    APPLY_RESULT_CANCEL(DictModelConstant.MODEL_APPLY,DictModelConstant.MODEL_APPLY_RESULT,"3","申请取消"),

    //流程审批操作类型
    Apply_APPROVAL_OPINION_REFUSE(DictModelConstant.MODEL_APPLY,DictModelConstant.MODEL_APPLY_APPROVAL_OPINION_FLAG,"0","拒绝"),
    Apply_APPROVAL_OPINION_AGREE(DictModelConstant.MODEL_APPLY,DictModelConstant.MODEL_APPLY_APPROVAL_OPINION_FLAG,"1","同意"),
    APPLY_APPROVAL_OPINION_REJECT(DictModelConstant.MODEL_APPLY,DictModelConstant.MODEL_APPLY_APPROVAL_OPINION_FLAG,"2","驳回"),
    APPLY_APPROVAL_OPINION_CONFIRM(DictModelConstant.MODEL_APPLY,DictModelConstant.MODEL_APPLY_APPROVAL_OPINION_FLAG,"3","确认"),
    APPLY_APPROVAL_OPINION_REAPPLY(DictModelConstant.MODEL_APPLY,DictModelConstant.MODEL_APPLY_APPROVAL_OPINION_FLAG,"4","继续申请"),
    APPLY_APPROVAL_OPINION_ABANDON(DictModelConstant.MODEL_APPLY,DictModelConstant.MODEL_APPLY_APPROVAL_OPINION_FLAG,"5","取消申请"),
    APPLY_APPROVAL_OPINION_ASSIGN(DictModelConstant.MODEL_APPLY,DictModelConstant.MODEL_APPLY_APPROVAL_OPINION_FLAG,"6","撤回到指定节点"),


    /*********************** 流程审批表单配置模块 *************************/
    //zshb_contact 表名
    FORMKEY_APPLY(DictModelConstant.MODEL_APPLY_CONFIG, DictModelConstant.MODEL_APPLY_CONFIG_FORMKEY, "leave", "请假"),
    FORMKEY_RECTIFY(DictModelConstant.MODEL_APPLY_CONFIG, DictModelConstant.MODEL_APPLY_CONFIG_FORMKEY, "zshb_contact", "工作联系单"),
    FORMKEY_PROBLEM(DictModelConstant.MODEL_APPLY_CONFIG, DictModelConstant.MODEL_APPLY_CONFIG_FORMKEY, "zshb_contact_problem", "问题跟踪"),
    ;


    DictEnum(String model, String code, String key, String value) {
        this.model = model;
        this.code = code;
        this.key = key;
        this.value = value;
    }

    private String model;
    private String code;
    private String key;
    private String value;

    /**
     * 返回字典值
     *
     * @param model
     * @param code
     * @param key
     * @return
     */
    public static String getValue(String model, String code, String key) {
        for (DictEnum dictEnum : DictEnum.values()) {
            if (dictEnum.getModel().equals(model) && dictEnum.getCode().equals(code) && dictEnum.getKey().equals(key)) {
                return dictEnum.getValue();
            }
        }
        return "其他";
    }

    /**
     * 返回模块枚举集合
     *
     * @param model
     * @param code
     * @return
     */
    public static List<DictEnum> getEnumList(String model, String code) {
        List<DictEnum> result = Arrays.stream(DictEnum.values())
                .filter(dictEnum -> dictEnum.getModel().equals(model) && dictEnum.getCode().equals(code))
                .collect(Collectors.toList());

        return result;
    }

    /**
     * 获取 数据字典 集合
     *
     * @param model
     * @param code
     * @return
     */
    public static List<DictVO> getDictVOList(String model, String code) {
        List<DictVO> list = Lists.newArrayList();
        for (DictEnum dictEnum : DictEnum.values()) {
            if (dictEnum.getModel().equals(model) && dictEnum.getCode().equals(code)) {
                DictVO vo = new DictVO();
                vo.setKey(dictEnum.getKey());
                vo.setValue(dictEnum.getValue());
                list.add(vo);
            }
        }
        return list;
    }

    @Data
    static class DictVO {
        private String key;
        private String value;
    }

}
