package com.jeequan.jeepay.db.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.*;

/**
 * <p>
 * 商户配置表
 * </p>
 *
 * @author [mybatis plus generator]
 * @since 2022-02-10
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_mch_config")
public class MchConfig implements Serializable {

    public static final String AREA_LOCAK_OPEN = "1";

    public static final String AREA_LOCAK_CLOSE = "0";

    @Data
    @AllArgsConstructor
    public static final class Option {

        private String configKey;

        private String configName;

        private String groupKey;

        private String type;

        private String defVal;

        public static Option APP_VOICE = new Option("appVoice", "是否启用app订单语音播报", "orderConfig", "radio", "1");
        public static Option QRC_ESCAPING = new Option("qrcEscaping", "是否启用码牌防逃单功能","orderConfig", "radio", "1");
        public static Option SELF_CASHIER_STATE = new Option("selfCashierState", "便捷收银台开关", "selfCashier", "radio", "0");
        public static Option WEB_CASHIER_STATE = new Option("webCashierState", "WEB收银台开关", "webCashier", "radio", "0");
        public static Option MEMBER_MODEL_STATE = new Option("memberModelState", "会员模块状态开关", "memberConfig", "radio", "1");
        public static Option MEMBER_PAY_STATE = new Option("memberPayState", "会员支付开关", "memberConfig", "radio", "0");
        public static Option MEMBER_CUSTOM_AMOUNT_STATE = new Option("memberCustomAmountState", "充值自定义金额", "memberConfig", "radio", "1");
        public static Option APPLYMENT_DEF_ISV_NO = new Option("applymentDefIsvNo", "入网时默认的渠道号", "applymentConfig", "radio", null);

        // 线下电子围栏默认值
        public static Option REGION_LOCK_OFFLINE = new Option("regionLock", "电子围栏标识", "applymentConfig", "radio", "1");
        // 线上电子围栏默认值
        public static Option REGION_LOCK_ONLINE = new Option("regionLock", "电子围栏标识", "applymentConfig", "radio", "0");

        public static List<Option> optionList = new ArrayList<>();

        static {
            optionList.add(APP_VOICE);
            optionList.add(QRC_ESCAPING);
            optionList.add(SELF_CASHIER_STATE);
            optionList.add(WEB_CASHIER_STATE);
            optionList.add(MEMBER_MODEL_STATE);
            optionList.add(MEMBER_PAY_STATE);
            optionList.add(MEMBER_CUSTOM_AMOUNT_STATE);
            optionList.add(APPLYMENT_DEF_ISV_NO);
            optionList.add(REGION_LOCK_OFFLINE);
            optionList.add(REGION_LOCK_ONLINE);
        }

        public static Option getFirstByConfigKey(String configKey) {
            for (Option option : optionList) {
                if (configKey.equals(option.configKey)) {
                    return option;
                }
            }

            return null;
        }
    }

    public static String getDefIsvKey(String ifCode) {
        return ifCode + "_DEF_ISV";
    }

    private static final long serialVersionUID=1L;

    // gw
    public static final LambdaQueryWrapper<MchConfig> gw(){
        return new LambdaQueryWrapper<>();
    }

    public static final String YES = "1";
    public static final String NO = "0";

    /** 是否启用app订单语音播报 **/
    public static final String APP_VOICE = "appVoice";
    /** 是否启用码牌防逃单功能 **/
    public static final String QRC_ESCAPING = "qrcEscaping";

    /** 便捷收银台LOGO及底部显示配置 **/
    public static final String SELF_CASHIER_SITEINFO_TYPE_DEFAULT = "DEFAULT";  // 默认
    public static final String SELF_CASHIER_SITEINFO_TYPE_NONE = "NONE";    // 为空
    public static final String SELF_CASHIER_SITEINFO_TYPE_CUSTOM = "CUSTOM";    // 自定义

    /** group key */
    public static final String SELF_CASHIER_GROUP_KEY = "selfCashier";
    public static final String WEB_CASHIER_GROUP_KEY = "webCashier";

    /** 便捷收银台 / web收银台 配置   **/
    public static final String SELF_CASHIER_STATE = "selfCashierState";
    public static final String SELF_CASHIER_SITEINFO_TYPE = "selfCashierSiteInfoType";
    public static final String SELF_CASHIER_WXH5_CONFIG = "selfCashierWxH5Config";
    public static final String SELF_CASHIER_ALIWAP_CONFIG = "selfCashierAliWapConfig";

    public static final String WEB_CASHIER_STATE = "webCashierState";
    public static final String WEB_CASHIER_SITEINFO_TYPE = "webCashierSiteInfoType";
    public static final String WEB_CASHIER_WXH5_CONFIG = "webCashierWxH5Config";
    public static final String WEB_CASHIER_ALIWAP_CONFIG = "webCashierAliWapConfig";

    /** 商户会员配置 **/
    public static final String SELF_MEMBER_MODEL_STATE = "memberModelState";
    public static final String SELF_MEMBER_PAY_STATE = "memberPayState";
    public static final String SELF_MEMBER_CUSTOM_AMOUNT_STATE = "memberCustomAmountState";
    public static final String SELF_MEMBER_MAX_BALANCE = "mbrMaxBalance";

    // app订单语音播报配置
    public static Map<String, String> appVoiceMap = new HashMap<>();
    static {
        appVoiceMap.put("configKey", "appVoice");
        appVoiceMap.put("configName", "是否启用app订单语音播报");
        appVoiceMap.put("configVal", "1");
        appVoiceMap.put("groupKey", "orderConfig");
        appVoiceMap.put("type", "radio");
    }

    // 码牌防逃单功能配置
    public static Map<String, String> qrcEscapingMap = new HashMap<>();
    static {
        qrcEscapingMap.put("configKey", "qrcEscaping");
        qrcEscapingMap.put("configName", "是否启用码牌防逃单功能");
        qrcEscapingMap.put("configVal", "1");
        qrcEscapingMap.put("groupKey", "orderConfig");
        qrcEscapingMap.put("type", "radio");
    }

    // 便捷收银台功能配置
    public static Map<String, String> selfCashierStateMap = new HashMap<>();
    static {
        selfCashierStateMap.put("configKey", "selfCashierState");
        selfCashierStateMap.put("configName", "便捷收银台开关");
        selfCashierStateMap.put("configVal", "0");
        selfCashierStateMap.put("groupKey", "selfCashier");
        selfCashierStateMap.put("type", "radio");
    }

    // WEB收银台功能配置
    public static Map<String, String> webCashierStateMap = new HashMap<>();
    static {
        webCashierStateMap.put("configKey", "webCashierState");
        webCashierStateMap.put("configName", "WEB收银台开关");
        webCashierStateMap.put("configVal", "0");
        webCashierStateMap.put("groupKey", "webCashier");
        webCashierStateMap.put("type", "radio");
    }

    // 商户会员功能开关
    public static Map<String, String> mchMemberModelMap = new HashMap<>();
    static {
        mchMemberModelMap.put("configKey", "memberModelState");
        mchMemberModelMap.put("configName", "会员模块状态开关");
        mchMemberModelMap.put("configVal", "1");
        mchMemberModelMap.put("groupKey", "memberConfig");
        mchMemberModelMap.put("type", "radio");
    }

    // 商户会员支付功能开关
    public static Map<String, String> mchMemberPayMap = new HashMap<>();
    static {
        mchMemberPayMap.put("configKey", "memberPayState");
        mchMemberPayMap.put("configName", "会员支付开关");
        mchMemberPayMap.put("configVal", "0");
        mchMemberPayMap.put("groupKey", "memberConfig");
        mchMemberPayMap.put("type", "radio");
    }

    // 商户会员自定义金额充值
    public static Map<String, String> mchMemberCustomAmountMap = new HashMap<>();
    static {
        mchMemberCustomAmountMap.put("configKey", "memberCustomAmountState");
        mchMemberCustomAmountMap.put("configName", "充值自定义金额");
        mchMemberCustomAmountMap.put("configVal", "1");
        mchMemberCustomAmountMap.put("groupKey", "memberConfig");
        mchMemberCustomAmountMap.put("type", "radio");
    }

    /**
     * 此处只做标记，不做默认存储
     */
    public static Map<String, String> mchApplymentDefSet = new HashMap<>();

    static {
        mchApplymentDefSet.put("configKey", "applymentDefIsvNo");
        mchApplymentDefSet.put("configName", "入网时默认的渠道号");
        mchApplymentDefSet.put("configVal", "");
        mchApplymentDefSet.put("groupKey", "applymentConfig");
        mchApplymentDefSet.put("type", "radio");
    }

    /**
     * 以下为默认配置参数
     */
    public static final List<Map<String, String>> configList = new LinkedList<>();
    static {
        configList.add(appVoiceMap);
        configList.add(qrcEscapingMap);
        configList.add(selfCashierStateMap);
        configList.add(webCashierStateMap);

        /** 会员配置 **/
        configList.add(mchMemberModelMap);
        configList.add(mchMemberPayMap);
        configList.add(mchMemberCustomAmountMap);
    }

    /** 不支持商户自行修改的配置项 **/
    public static final List<String> NOT_ALLOW_MCH_EDIT = new ArrayList<>();
    static {
        NOT_ALLOW_MCH_EDIT.add(SELF_MEMBER_MODEL_STATE);
        NOT_ALLOW_MCH_EDIT.add(SELF_MEMBER_MAX_BALANCE);
    }

    /**
     * 商户号
     */
    private String mchNo;

    /**
     * @since 2024-03-21
     * 商户应用ID，若配置是以商户号为维度，则该值为空
     */
    private String mchAppId;

    /**
     * @since 2024-03-21
     * 商户进件号，若配置是以商户号或应用为维度，则该值为空
     */
    private String mchApplyId;
    /**
     * 配置KEY
     */
    private String configKey;

    /**
     * 配置名称
     */
    private String configName;

    /**
     * 配置内容项
     */
    private String configVal;

    /**
     * 配置分组
     */
    private String groupKey;

    /**
     * 类型: text-输入框, textarea-多行文本, uploadImg-上传图片, switch-开关, radio-单选框
     */
    private String type;

    /**
     * 创建时间
     */
    private Date createdAt;

    /**
     * 更新时间
     */
    private Date updatedAt;

}
