package com.malk.lianan.model;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

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

/**
 * 定义返回值和对应状态的信息 [旧版本]
 * ppExt: 新版本官方返回数据已结构化, 以官方为准
 */
@Deprecated
@Slf4j
public enum McInvoiceKind {

    PP("增值税普通发票", 1),
    ZP("增值税专用发票", 2),
    DP("增值税电子普通发票", 3),
    DZ("增值税电子专用发票", 4),
    QP("全电普通发票", 5),
    QZ("全电专用发票", 6),

    HC("火车票", 11),
    JP("机票行程单", 12),
    CZC("出租车发票", 13),
    DE("定额发票", 14),
    GLGQ("过路过桥费发票", 15),

    FS("非税发票", 21),
    OT("其它特殊发票", 22),

    UN("未知类型", -1);

    @Getter
    private String desc;
    @Getter
    private int code;

    /**
     * 根据code查找
     */
    public final static String getKindName(int code) {
        Optional optional = Arrays.stream(McInvoiceKind.values()).filter(item -> item.code == code).findAny();
        if (optional.isPresent()) {
            return ((McInvoiceKind) optional.get()).desc;
        }
        return UN.getDesc();
    }

    /**
     * 根据name查找
     */
    public final static int getKindCode(String name) {
        Optional optional = Arrays.stream(McInvoiceKind.values()).filter(item -> item.desc.equals(name)).findAny();
        //log.info("发票类型, {}", Arrays.stream(McInvoiceKind.values()).map(item -> item.desc).collect(Collectors.toList()));
        if (optional.isPresent()) {
            return ((McInvoiceKind) optional.get()).code;
        }
        return UN.getCode();
    }

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