package com.sckw.core.model.enums;

import com.sckw.core.model.constant.Global;
import com.sckw.core.utils.StringUtils;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author czh
 * @desc 企业类型枚举
 * @date 2023/6/15
 */
@Getter
public enum EntTypeEnum {

    //供应商
    SUPPLIER(1, "供应商"),
    //采购商
    PURCHASER(2, "采购商"),
    LOGISTIC(3, "物流属性"),

    //4PL物流  托运 承运
    LOGISTICS3(3, "4PL物流"),
    //3PL物流  承运
    LOGISTICS4(4, "3PL物流");

    private final int code;

    private final String name;

    EntTypeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public static EntTypeEnum getName(int code) {
        for (EntTypeEnum entTypeEnum : values()) {
            if (entTypeEnum.getCode() == code) {
                return entTypeEnum;
            }
        }
        return null;
    }

    public static String getNames(String entTypes) {
        List entNames = new ArrayList();
        EntTypeEnum[] entTypeEnums = EntTypeEnum.values();
        for (EntTypeEnum entTypeEnum : entTypeEnums) {
            if (entTypes.contains(String.valueOf(entTypeEnum.getCode()))) {
                entNames.add(entTypeEnum.getName());
            }
        }
        return String.join(Global.COMMA, entNames);
    }

    /**
     * @param entTypes 企业属性
     * @desc 校验企业是否为托运单位（供应商、采购商、4P物流）
     * @author zk
     * @date 2023/10/7
     **/
    public static Boolean check(String entTypes) {
        if (StringUtils.isBlank(entTypes)) {
            return null;
        }
        return entTypes.contains(String.valueOf(EntTypeEnum.SUPPLIER.getCode()))
                || entTypes.contains(String.valueOf(EntTypeEnum.PURCHASER.getCode()))
                || entTypes.contains(String.valueOf(EntTypeEnum.LOGISTICS3.getCode()));
    }

    /**
     * @param entTypes 企业属性
     * @desc 校验企业是否为承运单位（4P物流、3P物流）
     * @author zk
     * @date 2023/10/7
     **/
    public static Boolean carrier(String entTypes) {
        if (StringUtils.isBlank(entTypes)) {
            return null;
        }
        return entTypes.contains(String.valueOf(EntTypeEnum.LOGISTICS3.getCode()))
                || entTypes.contains(String.valueOf(EntTypeEnum.LOGISTICS4.getCode()));
    }

    /**
     * @desc 获取企业是承运单位类型值（4P物流、3P物流）
     * @author zk
     * @date 2023/10/7
     **/
    public static String carrier() {
        return EntTypeEnum.LOGISTICS3.getCode() + Global.COMMA + EntTypeEnum.LOGISTICS4.getCode();
    }


}
