package com.njcn.gather.report.pojo.enums;

import lombok.Getter;

/**
 * 检测项模版枚举
 * @author hongawen
 * @version 1.0
 * @data 2025/3/27 10:24
 */
@Getter
public enum ItemReportKeyEnum {

    NAME("name", "检测项，比如：频率"),
    NAME_DETAIL("nameDetail", "检测项详细，比如：频率测量准确度"),
    INFLUENCE("influence", "影响量的描述，比如额定工作条件、谐波对电压的影响等等"),
    ERROR_SCOPE("errorScope", "误差范围，注：在段落中时需加上（），表格中无需添加"),
    A_ERROR_SCOPE("a_errorScope", "A级误差，比如：±0.1%Un\n(±0.05774)，需要换行，电压需要转为幅值"),
    NUM_OF_DATA("numOfData", "有效数据组数"),
    PHASE("phase", "相别"),
    ERROR_SCOPE_MAG("errorScopeMag", "特征幅值：误差范围"),
    ERROR_SCOPE_DUR("errorScopeDur", "持续时间：误差范围"),
    SCRIPT_DETAIL("scriptDetail", "脚本输出明细。比如：基波电压UN=57.74V，f=50Hz，谐波含有率Uh=10%UN=5.774V"),
    TIME("time", "次数"),
    STANDARD("standard", "标准值"),
    STANDARD_A("standardA", "A相标准值"),
    STANDARD_B("standardB", "B相标准值"),
    STANDARD_C("standardC", "C相标准值"),
    STANDARD_MAG("standardMag", "特征幅值的标准值"),
    STANDARD_DUR("standardDur_ms", "持续时间的标准值"),
    TEST("test", "测试值"),
    TEST_MAG("testMag", "特征幅值测试值"),
    TEST_DUR("testDur_ms", "持续时间测试值"),
    TEST_A("testA", "A相测试值"),
    TEST_B("testB", "B相测试值"),
    TEST_C("testC", "C相测试值"),
    ERROR("error", "误差"),
    ERROR_MAG("errorMag", "特征幅值误差"),
    ERROR_DUR("errorDur_ms", "持续时间误差"),
    ERROR_A("errorA", "A相误差"),
    ERROR_B("errorB", "B相误差"),
    ERROR_C("errorC", "C相误差"),
    RESULT("result", "结论 比如：合格/不合格"),
    RESULT_A("resultA", "结论 比如：合格/不合格"),
    RESULT_B("resultB", "结论 比如：合格/不合格"),
    RESULT_C("resultC", "结论 比如：合格/不合格"),
    RESULT_MAG("resultMag", "特征幅值结论 比如：合格/不合格"),
    RESULT_DUR("resultDur", "持续时间结论 比如：合格/不合格"),

    // ===== 以下为"指标锚点"新型模板（云南检定报告）新增 key，见 docs/superpowers/specs/2026-07-02-item-anchor-report-template-design.md §5 =====
    STANDARD_V("standardV", "P表：基波电压设置值"),
    STANDARD_I("standardI", "P表：基波电流设置值"),
    STANDARD_U_ANGLE("standardUAngle", "P表：电压相角设置值"),
    STANDARD_I_ANGLE("standardIAngle", "P表：电流相角设置值"),
    ACTIVE_POWER("activePower", "P表：有功功率实测值（三相之和）"),
    REACTIVE_POWER("reactivePower", "P表：无功功率实测值（数据侧暂无，留空）"),
    APPARENT_POWER("apparentPower", "P表：视在功率实测值（数据侧暂无，留空）"),
    POWER_FACTOR("powerFactor", "P表：功率因数实测值（数据侧暂无，留空）"),
    POS_SEQ("posSeq", "不平衡表：基波正序（数据侧暂无，留空）"),
    NEG_SEQ("negSeq", "不平衡表：基波负序（数据侧暂无，留空）"),
    ZERO_SEQ("zeroSeq", "不平衡表：基波零序（数据侧暂无，留空）"),
    BASE_CURRENT_A("baseCurrentA", "HI表：A相基波电流幅值，用于计算谐波电流含有率"),
    BASE_CURRENT_B("baseCurrentB", "HI表：B相基波电流幅值，用于计算谐波电流含有率"),
    BASE_CURRENT_C("baseCurrentC", "HI表：C相基波电流幅值，用于计算谐波电流含有率"),
    STANDARD_RATE("standardRate", "HI表：标准源输出含有率"),
    TEST_RATE_A("testRateA", "HI表：A相谐波电流含有率"),
    TEST_RATE_B("testRateB", "HI表：B相谐波电流含有率"),
    TEST_RATE_C("testRateC", "HI表：C相谐波电流含有率"),
    ERROR_RATE_A("errorRateA", "HI表：A相谐波电流含有率误差"),
    ERROR_RATE_B("errorRateB", "HI表：B相谐波电流含有率误差"),
    ERROR_RATE_C("errorRateC", "HI表：C相谐波电流含有率误差"),
    STANDARD_THD("standardThd", "HV/HI表：标准源总谐波畸变率"),
    THD_A("thdA", "HV/HI表：A相总谐波畸变率"),
    THD_B("thdB", "HV/HI表：B相总谐波畸变率"),
    THD_C("thdC", "HV/HI表：C相总谐波畸变率");

    private String key;

    private String desc;

    ItemReportKeyEnum(String key, String desc) {
        this.key = key;
        this.desc = desc;
    }

    /**
     * 根据key找到适配的枚举
     *
     * @param key 枚举的key
     * @return 匹配的枚举实例，如果没有找到则返回null
     */
    public static ItemReportKeyEnum getByKey(String key) {
        for (ItemReportKeyEnum itemReportKetEnum : ItemReportKeyEnum.values()) {
            if (itemReportKetEnum.getKey().equalsIgnoreCase(key)) {
                return itemReportKetEnum;
            }
        }
        return null;
    }

}
