package cn.superdesk.uniorder.common.enums.invoice.common;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 购方企业类型
 * @Author: linjinyu
 * @CreateDate: 2022/3/4 下午3:08
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/3/4 下午3:08
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public enum PurchaserCompanyTypeEnum {

    // 侨城汇提供了一份 关于开票导出 添加字段 当中 `购方企业类型` 为个人时 是 `04` mark by linjinyu at 20220322
    个人及非企业性机构(4, "03", "个人及非企业性机构"),
    企业(5, "01", "企业"),
    ;

    private Integer selectedInvoiceTitle;
    private String purchaserCompanyType;
    private String purchaserCompanyTypeName;

    PurchaserCompanyTypeEnum(Integer selectedInvoiceTitle, String purchaserCompanyType, String purchaserCompanyTypeName) {
        this.selectedInvoiceTitle = selectedInvoiceTitle;
        this.purchaserCompanyType = purchaserCompanyType;
        this.purchaserCompanyTypeName = purchaserCompanyTypeName;
    }

    public Integer getSelectedInvoiceTitle() {
        return selectedInvoiceTitle;
    }

    public String getPurchaserCompanyType() {
        return purchaserCompanyType;
    }

    public String getPurchaserCompanyTypeName() {
        return purchaserCompanyTypeName;
    }


    public static String getPurchaserCompanyType(Integer key) {
        for (PurchaserCompanyTypeEnum c : PurchaserCompanyTypeEnum.values()) {
            if (c.selectedInvoiceTitle.equals(key)) {
                return c.getPurchaserCompanyType();
            }
        }

        return "未知";
    }

    private static final Map<Integer, PurchaserCompanyTypeEnum> LOOKUP_SELECTEDINVOICETITLE = new HashMap<>();

    private static final Map<String, PurchaserCompanyTypeEnum> LOOKUP_PURCHASERCOMPANYTYPE = new HashMap<>();

    static {

        // 这个是统一订单的定义
        for (PurchaserCompanyTypeEnum s : EnumSet.allOf(PurchaserCompanyTypeEnum.class)) {
            LOOKUP_SELECTEDINVOICETITLE.put(s.getSelectedInvoiceTitle(), s);
        }
        // 这个是深圳航天的定义
        for (PurchaserCompanyTypeEnum s : EnumSet.allOf(PurchaserCompanyTypeEnum.class)) {
            LOOKUP_PURCHASERCOMPANYTYPE.put(s.getPurchaserCompanyType(), s);
        }
    }

    public static PurchaserCompanyTypeEnum getBySelectedInvoiceTitle(Integer selectedInvoiceTitle) {
        return LOOKUP_SELECTEDINVOICETITLE.get(selectedInvoiceTitle);
    }

    public static PurchaserCompanyTypeEnum getByPurchaserCompanyType(String purchaserCompanyType) {
        return LOOKUP_PURCHASERCOMPANYTYPE.get(purchaserCompanyType);
    }
}
