package com.starry.admin.modules.clerk.module.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;

/**
 * 店员资料类型枚举
 *
 * @author admin
 * @since 2024-05-19
 */
@ApiModel(value = "店员资料类型", description = "店员资料审核的数据类型枚举")
public enum ClerkDataType {

    NICKNAME("0", "昵称"),
    AVATAR("1", "头像"),
    PHOTO_ALBUM("2", "相册"),
    RECORDING("3", "录音"),
    GENDER("4", "性别");

    private final String code;
    private final String description;

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

    @JsonValue
    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举
     * @param code 代码
     * @return 枚举值
     */
    @JsonCreator
    public static ClerkDataType fromCode(String code) {
        if (code == null) {
            return null;
        }
        for (ClerkDataType type : ClerkDataType.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown code: " + code);
    }

    /**
     * 根据代码获取描述
     * @param code 代码
     * @return 描述
     */
    public static String getDescriptionByCode(String code) {
        ClerkDataType type = fromCode(code);
        return type != null ? type.description : null;
    }
}
