package com.zfire.jiasm.syncdata.constant;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Named;
import org.mapstruct.TargetType;

import java.util.Arrays;

/**
 * 服务类别
 * @author yaozx
 * @version 1.0
 * @date 2023-02-15
 */
@Getter
public enum ServiceCategoryEnum {

    /**
     * 服务类目
     */
    DICT_TYPE_SERVICE_CATEGORY("SERVICE_CATEGORY","家电售后"),
    /**
     * 安装
     */
    INSTALL_TYPE("INSTALL","安装"),

    /**
     * 维修
     */
    REPAIR_TYPE("REPAIR","维修"),

    /**
     * 配送
     */
    DELIVERY_TYPE("DELIVERY","配送"),

    /**
     * 服务品类-家用
     */
    HOME_TYPE("HOME","家用"),

    /**
     * 服务品类-商用
     */
    COMMERCIAL_TYPE("COMMERCIAL","商用"),

    ;



    /**
     * 编码
     */
    private final String code;


    private final String text;

    ServiceCategoryEnum(String code, String text) {
        this.code = code;
        this.text = text;
    }

    public static ServiceCategoryEnum getByCode(String code) {
        for (ServiceCategoryEnum item : values()) {
            if (code.equals(item.getCode())) {
                return item;
            }
        }
        return null;
    }

    public static ServiceCategoryEnum valueToEnum(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        return Arrays.stream(values())
                .filter(item -> item.getText().equals(value))
                .findAny()
                .orElse(null);
    }

    /**
     * 通过code获取枚举
     * @param code: code
     * @return 对应枚举
     **/
    public static String getMessageByCode(String code) {
        String result = null;
        for (ServiceCategoryEnum item : values()) {
            if (code.equals(item.getCode())) {
                result = item.getText();
                break;
            }
        }
        return result;
    }
}
