package com.lingyue.ai.enums;

import lombok.Getter;

/**
 * 实体类型枚举
 *
 * @author lingyue
 * @since 2026-01-19
 */
@Getter
public enum EntityType {

    PERSON("person", "人名"),
    ORG("org", "机构"),
    LOC("loc", "地点"),
    DATE("date", "日期"),
    NUMBER("number", "数值"),
    DEVICE("device", "设备"),
    TERM("term", "专业术语"),
    PROJECT("project", "项目"),
    COMPANY("company", "公司"),
    OTHER("other", "其他");

    private final String code;
    private final String description;

    EntityType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据 code 获取枚举
     */
    public static EntityType fromCode(String code) {
        if (code == null) {
            return OTHER;
        }
        for (EntityType type : values()) {
            if (type.code.equalsIgnoreCase(code) || type.name().equalsIgnoreCase(code)) {
                return type;
            }
        }
        return OTHER;
    }

    /**
     * 检查是否是有效的实体类型
     */
    public static boolean isValid(String code) {
        if (code == null) {
            return false;
        }
        for (EntityType type : values()) {
            if (type.code.equalsIgnoreCase(code) || type.name().equalsIgnoreCase(code)) {
                return true;
            }
        }
        return false;
    }
}
