package com.cool.store.enums;

import com.cool.store.utils.StringUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @Author: WangShuo
 * @Date: 2024/11/04/下午7:00
 * @Version 1.0
 * @注释:
 */
public enum FranchiseBrandEnum {
    ZXJP(1,"正新鸡排","option486","上海正新食品集团有限公司","海南正新多品牌管理有限公司"),
    ZXSMZ(2,"正新三明治","option622","上海小熊与树食品科技有限公司","上海小熊与树食品科技有限公司"),
    ZJS(3,"正烧记","option488","上海正烧信息科技有限公司","上海正烧信息科技有限公司"),
    DGMX(4,"大鼓米线","option624","",""),
    CXM(5,"串小妹","option626","",""),
    MZG(6,"茂掌柜","option490","","");
    private int code;
    private String desc;
    /**法大大合同编号*/
    private String hqtCode;
    /**品牌方*/
    private String brandOwner;
    /**收款方*/
    private String payeeName;

    FranchiseBrandEnum(int code, String desc,String hqtCode,String brandOwner,String payeeName) {
        this.code = code;
        this.desc = desc;
        this.hqtCode = hqtCode;
        this.brandOwner = brandOwner;
        this.payeeName = payeeName;
    }
    public int getCode() {
        return code;
    }
    public String getDesc() {
        return desc;
    }

    public String getHqtCode() {
        return hqtCode;
    }

    public String getBrandOwner() {
        return brandOwner;
    }

    public String getPayeeName() {
        return payeeName;
    }

    public static String getDescByCode(String code) {
        if (StringUtils.isBlank(code)){
            return null;
        }
        return Arrays.stream(code.split(","))
                .map(v -> {
                    FranchiseBrandEnum brand = getEnumByCode(v);
                    return Objects.nonNull(brand) ? brand.getDesc() : null;
                })
                .filter(StringUtils::isNotBlank)
                .collect(Collectors.joining(","));
    }

    public static FranchiseBrandEnum getEnumByCode(String code) {
        if (StringUtils.isBlank(code)){
            return null;
        }
        int i = Integer.parseInt(code);
        for (FranchiseBrandEnum e : FranchiseBrandEnum.values()) {
            if (i == e.getCode()) {
                return e;
            }
        }
        return null;
    }

    public static String getDescByCode(Integer code) {
        if (code==null){
            return null;
        }
        for (FranchiseBrandEnum e : FranchiseBrandEnum.values()) {
            if (code == e.getCode()) {
                return e.getDesc();
            }
        }
        return null;
    }

    public static FranchiseBrandEnum getEnumByCode(Integer code) {
        if (code == null){
            return null;
        }
        for (FranchiseBrandEnum e : FranchiseBrandEnum.values()) {
            if (code == e.getCode()) {
                return e;
            }
        }
        return null;
    }
}
