package com.mosquito.project.permission;

/**
 * 角色常量定义
 * 与前端 auth/roles.ts 中的 AdminRole 保持一致
 */
public final class RoleConstants {

    private RoleConstants() {
    }

    // ==================== 系统层角色 ====================
    /** 超级管理员 */
    public static final String SUPER_ADMIN = "super_admin";

    /** 系统管理员 */
    public static final String SYSTEM_ADMIN = "system_admin";

    // ==================== 管理层角色 ====================
    /** 运营总监 */
    public static final String OPERATION_DIRECTOR = "operation_director";

    /** 运营经理 */
    public static final String OPERATION_MANAGER = "operation_manager";

    /** 市场总监 */
    public static final String MARKETING_DIRECTOR = "marketing_director";

    /** 市场经理 */
    public static final String MARKETING_MANAGER = "marketing_manager";

    /** 财务经理 */
    public static final String FINANCE_MANAGER = "finance_manager";

    /** 风控经理 */
    public static final String RISK_MANAGER = "risk_manager";

    /** 客服主管 */
    public static final String CUSTOMER_SERVICE_LEADER = "cs_manager";

    // ==================== 执行层角色 ====================
    /** 运营专员 */
    public static final String OPERATION_SPECIALIST = "operation_specialist";

    /** 市场专员 */
    public static final String MARKETING_SPECIALIST = "marketing_specialist";

    /** 财务专员 */
    public static final String FINANCE_SPECIALIST = "finance_specialist";

    /** 风控专员 */
    public static final String RISK_SPECIALIST = "risk_specialist";

    /** 客服专员 */
    public static final String CS_AGENT = "cs_agent";

    // ==================== 审计层角色 ====================
    /** 审计员 */
    public static final String AUDITOR = "auditor";

    // ==================== 其他角色 ====================
    /** 只读用户 */
    public static final String VIEWER = "viewer";

    // ==================== 角色数组 ====================

    /** 所有角色代码数组 */
    public static final String[] ALL_ROLES = {
        SUPER_ADMIN,
        SYSTEM_ADMIN,
        OPERATION_DIRECTOR,
        OPERATION_MANAGER,
        MARKETING_DIRECTOR,
        MARKETING_MANAGER,
        FINANCE_MANAGER,
        RISK_MANAGER,
        CUSTOMER_SERVICE_LEADER,
        OPERATION_SPECIALIST,
        MARKETING_SPECIALIST,
        FINANCE_SPECIALIST,
        RISK_SPECIALIST,
        CS_AGENT,
        AUDITOR,
        VIEWER
    };

    /** 核心角色（不可删除）- 与PRD保持一致，共10个 */
    public static final String[] CORE_ROLES = {
        SUPER_ADMIN,
        SYSTEM_ADMIN,
        OPERATION_DIRECTOR,
        OPERATION_MANAGER,
        OPERATION_SPECIALIST,
        FINANCE_MANAGER,
        FINANCE_SPECIALIST,
        RISK_MANAGER,
        CUSTOMER_SERVICE_LEADER,
        AUDITOR
    };

    /** 拥有全部数据权限的角色 */
    public static final String[] ALL_DATA_SCOPE_ROLES = {
        SUPER_ADMIN,
        SYSTEM_ADMIN,
        AUDITOR
    };

    /** 拥有部门数据权限的角色（管理层） */
    public static final String[] DEPARTMENT_DATA_SCOPE_ROLES = {
        OPERATION_DIRECTOR,
        OPERATION_MANAGER,
        MARKETING_DIRECTOR,
        MARKETING_MANAGER,
        FINANCE_MANAGER,
        RISK_MANAGER,
        CUSTOMER_SERVICE_LEADER
    };

    /** 拥有个人数据权限的角色（执行层） */
    public static final String[] OWN_DATA_SCOPE_ROLES = {
        OPERATION_SPECIALIST,
        MARKETING_SPECIALIST,
        FINANCE_SPECIALIST,
        RISK_SPECIALIST,
        CS_AGENT,
        VIEWER
    };

    /**
     * 判断是否为超级管理员
     */
    public static boolean isSuperAdmin(String roleCode) {
        return SUPER_ADMIN.equals(roleCode);
    }

    /**
     * 判断是否为系统管理员
     */
    public static boolean isSystemAdmin(String roleCode) {
        return SYSTEM_ADMIN.equals(roleCode);
    }

    /**
     * 判断是否为审计员
     */
    public static boolean isAuditor(String roleCode) {
        return AUDITOR.equals(roleCode);
    }

    /**
     * 判断是否为核心角色（不可删除）
     */
    public static boolean isCoreRole(String roleCode) {
        for (String coreRole : CORE_ROLES) {
            if (coreRole.equals(roleCode)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 判断是否拥有全部数据权限
     */
    public static boolean hasAllDataScope(String roleCode) {
        for (String role : ALL_DATA_SCOPE_ROLES) {
            if (role.equals(roleCode)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 判断是否拥有部门数据权限
     */
    public static boolean hasDepartmentDataScope(String roleCode) {
        for (String role : DEPARTMENT_DATA_SCOPE_ROLES) {
            if (role.equals(roleCode)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 判断是否拥有个人数据权限
     */
    public static boolean hasOwnDataScope(String roleCode) {
        for (String role : OWN_DATA_SCOPE_ROLES) {
            if (role.equals(roleCode)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 根据角色代码获取默认数据权限范围
     * @return "ALL", "DEPARTMENT", 或 "OWN"
     */
    public static String getDefaultDataScope(String roleCode) {
        if (hasAllDataScope(roleCode)) {
            return "ALL";
        } else if (hasDepartmentDataScope(roleCode)) {
            return "DEPARTMENT";
        } else {
            return "OWN";
        }
    }
}
