package com.fs.his.enums.hsyy;

/**
 * @Author：peicj
 * @Description: 性别
 * @Date：2026/1/5 11:10
 */
public enum Gender {

    UNKNOWN(0, "未知"),
    MALE(1, "男"),
    FEMALE(2, "女"),
    OTHER(9, "其他");

    private final int code;
    private final String description;

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

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    // 根据code获取枚举
    public static Gender fromCode(int code) {
        for (Gender gender : values()) {
            if (gender.code == code) {
                return gender;
            }
        }
        return UNKNOWN; // 默认返回未知
    }

    // 根据code获取描述
    public static String getDescriptionByCode(int code) {
        return fromCode(code).getDescription();
    }

    // 根据描述获取code
    public static int getCodeByDescription(String description) {
        for (Gender gender : values()) {
            if (gender.description.equals(description)) {
                return gender.code;
            }
        }
        return UNKNOWN.code;
    }
}
