package com.fkzy.warn.common.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhangjing
 * @date 2026/03/10 18:04
 * @description
 */
public enum CaseRoleMapping {

    // 民事
    CIVIL_PLAINTIFF("civil", "原告", "原告"),
    CIVIL_DEFENDANT("civil", "被告", "被告"),
    CIVIL_COUNTER_PLAINTIFF("civil", "反诉原告", "原告"),
    CIVIL_COUNTER_DEFENDANT("civil", "反诉被告", "被告"),
    CIVIL_THIRD_PARTY("civil", "第三人", "第三人"),
    CIVIL_APPELLANT("civil", "上诉人", "原告"),
    CIVIL_RESPONDENT("civil", "被上诉人", "被告"),
    CIVIL_ORIGINAL_PLAINTIFF("civil", "原审原告", "原告"),
    CIVIL_ORIGINAL_DEFENDANT("civil", "原审被告", "被告"),
    CIVIL_ORIGINAL_THIRD_PARTY("civil", "原审第三人", "第三人"),
    CIVIL_ORIGINAL_APPLICANT("civil", "原审申请人", "原告"),
    CIVIL_ORIGINAL_RESPONDENT("civil", "原审被申请人", "被告"),

    // 刑事
    CRIMINAL_DEFENDANT("criminal", "被告人", "被告"),
    CRIMINAL_PRIVATE_PROSECUTOR("criminal", "自诉人", "原告"),
    CRIMINAL_COUNTER_PLAINTIFF("criminal", "反诉人", "原告"),
    CRIMINAL_COUNTER_DEFENDANT("criminal", "反诉被告人", "被告"),
    CRIMINAL_CIVIL_PLAINTIFF("criminal", "附带民事诉讼原告", "原告"),
    CRIMINAL_CIVIL_DEFENDANT("criminal", "附带民事诉讼被告", "被告"),
    CRIMINAL_CIVIL_COUNTER_PLAINTIFF("criminal", "附带民事诉讼反诉原告", "原告"),
    CRIMINAL_CIVIL_COUNTER_DEFENDANT("criminal", "附带民事诉讼反诉被告", "被告"),
    CRIMINAL_APPELLANT("criminal", "上诉人", "原告"),
    CRIMINAL_ORIGINAL_DEFENDANT_2("criminal", "原审被告人", "被告"),
    CRIMINAL_ORIGINAL_CIVIL_PLAINTIFF("criminal", "原审附带民事诉讼原告", "原告"),
    CRIMINAL_ORIGINAL_CIVIL_DEFENDANT("criminal", "原审附带民事诉讼被告", "被告"),
    CRIMINAL_REVIEW_APPLICANT("criminal", "申请复议人", "原告"),
    CRIMINAL_ORIGINAL_RESPONDENT_2("criminal", "原审被申请人", "被告"),
    CRIMINAL_INTERESTED_PARTY("criminal", "原审利害关系人", "第三人"),
    CRIMINAL_SUSPECT("criminal", "犯罪嫌疑人", "被告"),
    CRIMINAL_ORIGINAL_COUNTER_DEFENDANT("criminal", "原审反诉被告人", "被告"),
    CRIMINAL_ORIGINAL_COUNTER_PLAINTIFF("criminal", "原审反诉人", "原告"),

    // 行政
    ADMINISTRATIVE_PLAINTIFF("administrative", "原告", "原告"),
    ADMINISTRATIVE_DEFENDANT("administrative", "被告", "被告"),
    ADMINISTRATIVE_THIRD_PARTY("administrative", "第三人", "第三人"),
    ADMINISTRATIVE_APPELLANT("administrative", "上诉人", "原告"),
    ADMINISTRATIVE_RESPONDENT("administrative", "被上诉人", "被告"),
    ADMINISTRATIVE_ORIGINAL_PLAINTIFF("administrative", "原审原告", "原告"),
    ADMINISTRATIVE_ORIGINAL_DEFENDANT("administrative", "原审被告", "被告"),
    ADMINISTRATIVE_ORIGINAL_THIRD_PARTY("administrative", "原审第三人", "第三人"),

    // 非诉保全审查
    NON_LITIGATION_APPLICANT("preservation", "申请人", "原告"),
    NON_LITIGATION_RESPONDENT("preservation", "被申请人", "被告"),

    // 执行
    ENFORCEMENT_APPLICANT("implement", "申请执行人", "原告"),
    ENFORCEMENT_RESPONDENT("implement", "被执行人", "被告"),
    ENFORCEMENT_OBJECTOR("implement", "异议人", "第三人"),
    ENFORCEMENT_REVIEW_APPLICANT("implement", "申请复议人", "原告"),
    ENFORCEMENT_INTERESTED_PARTY("implement", "利害关系人", "第三人"),
    ENFORCEMENT_OUTSIDER("implement", "案外人", "第三人"),
    ENFORCEMENT_APPLICANT_GENERIC("implement", "申请人", "原告"),
    ENFORCEMENT_RESPONDENT_GENERIC("implement", "被申请人", "被告"),
    ENFORCEMENT_THIRD_PARTY("implement", "第三人", "第三人"),

    // 强制清算与破产
    BANKRUPTCY_APPLICANT("bankrupt", "申请人", "原告"),
    BANKRUPTCY_RESPONDENT("bankrupt", "被申请人", "被告"),
    BANKRUPTCY_SUPERVISION_APPELLANT("bankrupt", "原审上诉人", "原告"),
    BANKRUPTCY_SUPERVISION_RESPONDENT("bankrupt", "原审被上诉人", "被告"),
    BANKRUPTCY_ORIGINAL_APPLICANT("bankrupt", "原审申请人", "原告"),
    BANKRUPTCY_ORIGINAL_RESPONDENT("bankrupt", "原审被申请人", "被告"),
    BANKRUPTCY_APPEAL_APPELLANT("bankrupt", "上诉人", "原告"),
    BANKRUPTCY_APPEAL_RESPONDENT("bankrupt", "被上诉人", "被告"),

    // 通用兜底
    OTHER("所有类型", "其他", "第三人");

    private static final Map<String, String> MAPPING = new HashMap<>();

    static {
        for (CaseRoleMapping mapping : values()) {
            String key = buildKey(mapping.caseType, mapping.roleKey);
            MAPPING.put(key, mapping.statCategory);
        }
    }

    private final String caseType;
    private final String roleKey;
    private final String statCategory;

    CaseRoleMapping(String caseType, String roleKey, String statCategory) {
        this.caseType = caseType;
        this.roleKey = roleKey;
        this.statCategory = statCategory;
    }

    private static String buildKey(String caseType, String roleKey) {
        return caseType + "|" + roleKey;
    }

    /**
     * 根据案件类型和域值获取统计分类
     *
     * @param caseType 案件类型，如 "civil"、"criminal" 等
     * @param roleKey  域值，如 "原告"、"上诉人" 等
     * @return 对应的统计分类，如未找到则返回 null
     */
    public static String getStatCategory(String caseType, String roleKey) {
        if (caseType == null || roleKey == null) {
            return "第三人";
        }
        String result = MAPPING.get(buildKey(caseType, roleKey));
        if (result==null){
            return "第三人";
        }
        return result;
    }
}
