package com.lesingle.creation.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 性别枚举
 */
@Getter
@AllArgsConstructor
public enum GenderEnum {

    MALE("male", "男"),
    FEMALE("female", "女");

    private final String code;
    private final String desc;

    public static GenderEnum getByCode(String code) {
        if (code == null) {
            return null;
        }
        for (GenderEnum gender : values()) {
            if (gender.getCode().equals(code)) {
                return gender;
            }
        }
        return null;
    }

    /**
     * 根据数字代码获取性别
     * @param code 1-男，2-女
     * @return 性别枚举
     */
    public static GenderEnum getByIntCode(Integer code) {
        if (code == null) {
            return null;
        }
        if (code == 1) {
            return MALE;
        } else if (code == 2) {
            return FEMALE;
        }
        return null;
    }
}
