package com.ruoyi.common.constant;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

import cn.hutool.core.lang.Dict;
import com.ruoyi.project.business.domain.TbArea;
import com.ruoyi.project.business.domain.TbCountry;
import com.ruoyi.project.business.domain.TpParaLibrary;
import com.ruoyi.project.business.domain.TpParaSelectItem;
import com.ruoyi.project.business.enums.RoleEnum;
import com.ruoyi.project.system.domain.SysDictData;
import io.jsonwebtoken.Claims;

import static com.ruoyi.project.business.enums.RoleEnum.*;

/**
 * 通用常量信息
 * 
 * @author ruoyi
 */
public class Constants {
    /**
     * UTF-8 字符集
     */
    public static final String UTF8 = "UTF-8";

    /**
     * GBK 字符集
     */
    public static final String GBK = "GBK";

    /**
     * 系统语言
     */
    public static final Locale DEFAULT_LOCALE = Locale.SIMPLIFIED_CHINESE;

    /**
     * www主域
     */
    public static final String WWW = "www.";

    /**
     * http请求
     */
    public static final String HTTP = "http://";

    /**
     * https请求
     */
    public static final String HTTPS = "https://";

    /**
     * 通用成功标识
     */
    public static final String SUCCESS = "0";

    /**
     * 通用失败标识
     */
    public static final String FAIL = "1";

    /**
     * 登录成功
     */
    public static final String LOGIN_SUCCESS = "Success";

    /**
     * 注销
     */
    public static final String LOGOUT = "Logout";

    /**
     * 注册
     */
    public static final String REGISTER = "Register";

    /**
     * 登录失败
     */
    public static final String LOGIN_FAIL = "Error";

    /**
     * 所有权限标识
     */
    public static final String ALL_PERMISSION = "*:*:*";

    /**
     * 管理员角色权限标识
     */
    public static final String SUPER_ADMIN = "admin";
    /**
     * 系统管理员角色权限标识
     */
    public static final String SYSTEM_ADMIN = "system_manager";
    

    /**
     * VP 销售总监
     */
    public static final String VP_SALES_DIRECTOR = "sales_director";

    /**
     * 角色权限分隔符
     */
    public static final String ROLE_DELIMETER = ",";

    /**
     * 权限标识分隔符
     */
    public static final String PERMISSION_DELIMETER = ",";

    /**
     * 验证码有效期（分钟）
     */
    public static final Integer CAPTCHA_EXPIRATION = 2;

    /**
     * 令牌
     */
    public static final String TOKEN = "token";

    /**
     * 令牌前缀
     */
    public static final String TOKEN_PREFIX = "Bearer ";

    /**
     * 令牌前缀
     */
    public static final String LOGIN_USER_KEY = "login_user_key";

    /**
     * 用户ID
     */
    public static final String JWT_USERID = "userid";

    /**
     * 用户名称
     */
    public static final String JWT_USERNAME = Claims.SUBJECT;

    /**
     * 用户头像
     */
    public static final String JWT_AVATAR = "avatar";

    /**
     * 创建时间
     */
    public static final String JWT_CREATED = "created";

    /**
     * 用户权限
     */
    public static final String JWT_AUTHORITIES = "authorities";

    /**
     * 资源映射路径 前缀
     */
    public static final String RESOURCE_PREFIX = "/profile";

    /**
     * RMI 远程方法调用
     */
    public static final String LOOKUP_RMI = "rmi:";

    /**
     * LDAP 远程方法调用
     */
    public static final String LOOKUP_LDAP = "ldap:";

    /**
     * LDAPS 远程方法调用
     */
    public static final String LOOKUP_LDAPS = "ldaps:";

    /**
     * 自动识别json对象白名单配置（仅允许解析的包名，范围越小越安全）
     */
    public static final String[] JSON_WHITELIST_STR = {"org.springframework", "com.ruoyi"};

    /**
     * 定时任务白名单配置（仅允许访问的包名，如其他需要可以自行添加）
     */
    public static final String[] JOB_WHITELIST_STR = {"com.ruoyi.framework.task", "com.ruoyi.project.business.task"};

    /**
     * 定时任务违规的字符
     */
    public static final String[] JOB_ERROR_STR = {"java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
            "org.springframework", "org.apache", "com.ruoyi.common.utils.file", "com.ruoyi.framework.config", "com.ruoyi.project.tool"};

    /**
     * 默认地区
     */
    public static final String LOCAL_ZONE = "Asia/Shanghai";

    //TODO 可以使用 org.apache.poi.util.LocaleID 替换？

    /**
     * 中国
     */
    public static final String CN = "CN";

    /**
     * 美国
     */
    public static final String US = "US";

    /**
     * 俄罗斯
     */
    public static final String RU = "RU";

    /**
     * 西班牙
     */
    public static final String ES = "ES";

    /**
     * 中国
     */
    public static Locale ZH_LOCALE = Locale.CHINA;

    /**
     * 美国
     */
    public static Locale EN_LOCALE = Locale.US;

    /**
     * 俄罗斯
     */
    public static Locale RU_LOCALE = new Locale("ru", RU);

    /**
     * 西班牙
     */
    public static Locale ES_LOCALE = new Locale("es", ES);

    /**
     * 资料库 资源映射路径 前缀
     */
    public static final String TRAIN_RESOURCE_PREFIX = "/train-profile";

    /**
     * 区域 国际化name 映射方法
     */
    public static final Map<String, Function<TbArea, String>> AREA_LOCAL_NAME_FUN = new HashMap<String, Function<TbArea, String>>(5) {{
        put(CN, TbArea::getAreaName);
        put(US, TbArea::getAreaNameUS);
        put(RU, TbArea::getAreaNameRU);
        put(ES, TbArea::getAreaNameES);
        put("", TbArea::getAreaName);
    }};

    /**
     * 国家 国际化name 映射方法
     */
    public static final Map<String, Function<TbCountry, String>> COUNTRY_LOCAL_NAME_FUN = new HashMap<String, Function<TbCountry, String>>(5) {{
        put(CN, TbCountry::getCountryName);
        put(US, TbCountry::getCountryNameUS);
        put(RU, TbCountry::getCountryNameRU);
        put(ES, TbCountry::getCountryNameES);
        put("", TbCountry::getCountryName);
    }};

    /**
     * 参数库 国际化name 映射方法
     */
    public static final Map<String, Function<TpParaLibrary, String>> PARA_LOCAL_NAME_FUN = new HashMap<String, Function<TpParaLibrary, String>>(5) {{
        put(CN, TpParaLibrary::getParaName);
        put(US, TpParaLibrary::getParaNameUS);
        put(RU, TpParaLibrary::getParaNameRU);
        put(ES, TpParaLibrary::getParaNameES);
        put("", TpParaLibrary::getParaName);
    }};

    /**
     * 参数选项 国际化name 映射方法
     */
    public static final Map<String, Function<TpParaSelectItem, String>> PARA_ITEM_LOCAL_NAME_FUN = new HashMap<String, Function<TpParaSelectItem, String>>(5) {{
        put(CN, TpParaSelectItem::getLabel);
        put(US, TpParaSelectItem::getLabelUS);
        put(RU, TpParaSelectItem::getLabelRU);
        put(ES, TpParaSelectItem::getLabelES);
        put("", TpParaSelectItem::getLabel);
    }};

    /**
     * 字典 国际化label 映射方法
     */
    public static final Map<String, Function<SysDictData, String>> DICT_LOCAL_LABEL_FUN = new HashMap<String, Function<SysDictData, String>>(5) {{
        put(CN, SysDictData::getDictLabel);
        put(US, SysDictData::getDictLabelUS);
        put(RU, SysDictData::getDictLabelRU);
        put(ES, SysDictData::getDictLabelES);
        put("", SysDictData::getDictLabel);
    }};

    /**
     * 销售角色：VP、区总，销售经理，代理商经理、代理商销售、(销售支持 不是）
     */
    // public static final List<String> SALE_ROLES2 = Arrays.asList(RoleEnum.SALES_DIRECTOR.getKey(), RoleEnum.AREA_SALES_DIRECTOR.getKey(),
    //         RoleEnum.SALES_MANAGER.getKey(), RoleEnum.AGENT_SALES.getKey(), RoleEnum.AGENT_MANAGER.getKey(), RoleEnum.SALES_SUPPORT.getKey());

    public static final List<String> SALE_ROLES = roleKeys(SALES_DIRECTOR, AREA_SALES_DIRECTOR, SALES_MANAGER, AGENT_SALES, AGENT_MANAGER);


    public static final Set<String> FILE_TYPE_WORD = new HashSet<>(java.util.Arrays.asList("doc", "docx"));
    public static final Set<String> FILE_TYPE_EXCEL = new HashSet<>(java.util.Arrays.asList("xls", "xlsx"));
    public static final Set<String> FILE_TYPE_PPT = new HashSet<>(java.util.Arrays.asList("ppt", "pptx"));
    public static final Set<String> FILE_TYPE_OFFICE = new HashSet<>(java.util.Arrays.asList("doc", "docx", "xls", "xlsx", "ppt", "pptx"));
}
