package jnpf.model.warningnotice.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import jnpf.util.StringUtil;
import lombok.Setter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 证照类型枚举
 */
public enum CertificateTypeEnum {

    /**
     * 健康证
     */
    HEALTH_CERTIFICATE("healthCertificate", "健康证"),

    /**
     * 营业执照
     */
    BUSINESS_LICENSE("businessLicense", "营业执照"),

    /**
     * 卫生许可
     */
    HYGIENE_LICENSE("hygieneLicense", "食品经营许可证"),

    /**
     * 门店自定义证照
     */
    STORE_CUSTOM_CERTIFICATE("storeCustomCertificate", "门店自定义证照");

    private final String type;
    private final String label;

    CertificateTypeEnum(String type, String label) {
        this.type = type;
        this.label = label;
    }

    @JsonValue
    public String getType() {
        return type;
    }

    public String getLabel() {
        return label;
    }

    /**
     * 根据字符串解析证照类型，兼容枚举名和英文类型值
     *
     * @param type 证照类型文本
     * @return 证照类型枚举，未匹配返回null
     */
    @JsonCreator
    public static Optional<CertificateTypeEnum> getByType(String type) {
        if(StringUtil.isBlank(type)){
            return Optional.empty();
        }
        for (CertificateTypeEnum value : CertificateTypeEnum.values()){
            if(value.getType().equals( type)){
                return Optional.of(value);
            }
        }
        return Optional.of(CertificateTypeEnum.STORE_CUSTOM_CERTIFICATE);
    }
}