package com.qmth.paper.library.common.entity;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.qmth.paper.library.common.base.BaseEntity;
import com.qmth.paper.library.common.bean.dto.syssetting.SettingObject;
import com.qmth.paper.library.common.bean.dto.syssetting.SimpleObject;
import com.qmth.paper.library.common.contant.SysSettingConstant;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 系统设置表
 * </p>
 */
@TableName("sys_setting_global")
public class SysSettingGlobal extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 是否开启全局匹配
     */
    @TableField("parameter_object")
    private String parameterObject;

    public String getParameterObject() {
        return parameterObject;
    }

    public void setParameterObject(String parameterObject) {
        this.parameterObject = parameterObject;
    }

    /**
     * 初始化数据
     */
    public static SysSettingGlobal init() {
        List<SettingObject> settingObjects = new ArrayList<>();
        List<SimpleObject> simpleObjects1 = new ArrayList<>();
        simpleObjects1.add(new SimpleObject(SysSettingConstant.SYS_INIT_PASSWORD, "默认初始登录密码", "123456", 1, true, null, null));
        simpleObjects1.add(new SimpleObject(SysSettingConstant.SYS_FILE_HOST_URL, "文件访问地址", "", 2, true, null, null));
        simpleObjects1.add(new SimpleObject(SysSettingConstant.SYS_TXT_CHARSET, "异步任务txt日志文件编码", "gbk", 3, true, null, null));

        settingObjects.add(new SettingObject("系统设置", 1, simpleObjects1));

        List<SimpleObject> simpleObjects2 = new ArrayList<>();
        simpleObjects2.add(new SimpleObject(SysSettingConstant.OCR_APP_ID, "OCR AppId", "", 1, true, null, null));
        simpleObjects2.add(new SimpleObject(SysSettingConstant.OCR_APP_KEY, "OCR AppKey", "", 2, true, null, null));
        simpleObjects2.add(new SimpleObject(SysSettingConstant.OCR_APP_SECRET, "OCR AppSecret", "", 3, true, null, null));

        settingObjects.add(new SettingObject("OCR参数设置", 2, simpleObjects2));

        List<SimpleObject> simpleObjects3 = new ArrayList<>();
        simpleObjects3.add(new SimpleObject(SysSettingConstant.SYS_VERIFICATION_CODE_EXPIRED_TIME, "验证码有效时间（分钟）", "2", 1, true, null, null));
        simpleObjects3.add(new SimpleObject(SysSettingConstant.SYS_VERIFICATION_CODE_SEND_INTERVAL, "验证码发送频率（秒）", "60", 2, true, null, null));

        settingObjects.add(new SettingObject("短信参数设置", 3, simpleObjects3));

        SysSettingGlobal sysSetting = new SysSettingGlobal();
        sysSetting.setParameterObject(JSON.toJSONString(settingObjects));
        return sysSetting;
    }
}
