package com.dxhy.domestic.util;

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

import org.apache.commons.lang3.StringUtils;

import com.dxhy.common.enums.FpztEnum;
import com.dxhy.common.enums.QsTypeEnum;
import com.dxhy.common.enums.RzclztEnum;
import com.dxhy.common.enums.RzlxEnum;
import com.dxhy.common.enums.RzztEnum;

/**
 * @author dxhy
 */
public class InvoiceTypeUtils {

    public static String invoiceTypeName(String invoiceType) {
        String invoiceName = "";
        if (StringUtils.isNotBlank(invoiceType)) {
            switch (invoiceType) {
                case "01":
                    invoiceName = "增值税专用发票";
                    break;
                case "03":
                    invoiceName = "机动车销售统一发票";
                    break;
                case "04":
                    invoiceName = "增值税普通发票";
                    break;
                case "10":
                    invoiceName = "增值税电子普通发票";
                    break;
                case "11":
                    invoiceName = "增值税普通发票（卷票）";
                    break;
                case "14":
                    invoiceName = "增值税电子普通发票（通行费）";
                    break;
                case "08":
                    invoiceName = "增值税电子专用发票";
                    break;
                case "15":
                    invoiceName = "二手车销售统一发票";
                    break;
                default:
                    break;
            }
        }
        return invoiceName;
    }

    public static String rzztEnumTransfer(String authenticationStatus) {
        List<RzztEnum> result = Arrays.stream(RzztEnum.values()).filter(e -> e.getRzztDm().equals(authenticationStatus))
            .collect(Collectors.toList());

        if (result.isEmpty()) {
            return "未知类型";
        }
        RzztEnum rzztEnum = result.get(0);
        return rzztEnum.getRzztMc(rzztEnum.getIndex());

    }

    public static String authenticationTypeTransfer(String authenticationType) {
        return "退税".equals(RzlxEnum.getVal(authenticationType)) ? "退税认证" : RzlxEnum.getVal(authenticationType);
    }

    public static String rzclztEnumTransfer(String authenticationDetailStatus) {

        List<RzclztEnum> result = Arrays.stream(RzclztEnum.values())
            .filter(e -> e.getRzclztDm().equals(authenticationDetailStatus)).collect(Collectors.toList());

        if (result.isEmpty()) {
            switch (authenticationDetailStatus) {
                case "1":
                    return "抵扣";
                case "2":
                    return "退税";
                case "3":
                    return "代理退税";
                case "4":
                    return "不抵扣";
                case "5":
                    return "撤销认证";
                case "6":
                    return "撤销不抵扣";
                default:
                    return "未知类型";
            }
        }
        RzclztEnum rzztEnum = result.get(0);
        return rzztEnum.getRzclztMc(rzztEnum.getIndex());

    }

    public static String signInStatusTransfer(String code) {
        return "1".equals(code) ? "已签收" : "未签收";
    }

    public static String signInTypeTransfer(String type) {
        return QsTypeEnum.getVal(type);
    }

    public static String authenticationStatusConvert(String code) {
        RzztEnum collect =
            Arrays.stream(RzztEnum.values()).filter(e -> e.getRzztDm().equals(code)).findFirst().orElse(null);
        if (collect == null) {
            switch (code) {
                case "0":
                    return "未认证";
                case "1":
                    return "已认证抵扣";
                case "2":
                    return "已认证不抵扣";
                case "3":
                    return "已认证";
                default:
                    return "未知类型";
            }
        }
        // 测试提的bug，非要统一跟查询条件文字一致，懒得改枚举，凑合用吧
        String result = collect.getRzztMc(collect.getIndex());
        return "退税认证".equals(result) ? "已认证" : result;
    }

    public static String invoiceStatusConvert(String status) {
        return FpztEnum.getEnumMap().get(status);
    }

    public static String getRzzt(String rzhYesorno) {
        String rzzt = "";
        if (RzztEnum.WRZ.getRzztDm().equals(rzhYesorno)) {
            rzzt = RzztEnum.WRZ.getRzztMc(RzztEnum.WRZ.getIndex());
        } else if (RzztEnum.YRZ.getRzztDm().equals(rzhYesorno)) {
            rzzt = RzztEnum.YRZ.getRzztMc(RzztEnum.YRZ.getIndex());
        } else if (RzztEnum.YRZBDK.getRzztDm().equals(rzhYesorno)) {
            rzzt = RzztEnum.YRZBDK.getRzztMc(RzztEnum.YRZBDK.getIndex());
        } else if (RzztEnum.TSRZ.getRzztDm().equals(rzhYesorno)) {
            rzzt = RzztEnum.TSRZ.getRzztMc(RzztEnum.TSRZ.getIndex());
        }
        return rzzt;
    }

}
