package com.sonic.lion.utils;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.common.collect.Sets;
import com.sonic.lion.domain.entity.AccountBuffBill;
import com.sonic.lion.domain.enums.InOrOut;
import com.sonic.lion.enums.BizType;
import com.sonic.lion.enums.I18nResources;

import java.util.Set;

public class NoDisplayBizNumSet {

    //不返回交易号 的这些业务类型
    public static final Set<BizType> tradeNoSets = Sets.newHashSet(BizType.CHARGE, BizType.WITHDRAW
    );

    //返回 desc字段的 业务类型
    public static final Set<BizType> simpleDescSets = Sets.newHashSet(
            BizType.CHARGE);


    //处理Income Outcome的翻译。
    public static final Set<BizType> inOrOutBizTypeSets = Sets.newHashSet();


    public static String getItemDesc(AccountBuffBill buffBill, boolean mobile) {
        BizType bizType = buffBill.getBizType();
        InOrOut inOrOut = buffBill.getInOrOut();

        //TODO 先暂时写死描述，有待完善
        if (bizType != null) {
            return bizType.getDesc();
        }

        // 先处理移动端口 和  web 异同之处
        if (BizType.WITHDRAW.equals(bizType) && mobile) {
            if (inOrOut == InOrOut.IN) {
                return I18nResources.BILL_OTHER_INCOME.getI18n();
            } else if (inOrOut == InOrOut.OUT) {
                return I18nResources.BILL_OTHER_OUTCOME.getI18n();
            }
        }
        if (BizType.WITHDRAW.equals(bizType) && !mobile) {
            if (buffBill.getWithdrawStatus() != null && AccountBuffBill.WithdrawStatus.WITHDRAW_FAIL_BACK.equals(buffBill.getWithdrawStatus())) {
                return I18nResources.BILL_WITHDRAW_FAIL_BACK.getI18n();
            }
            if (inOrOut == InOrOut.IN) {
                return I18nResources.BILL_WITHDRAW_FAIL.getI18n();
            } else if (inOrOut == InOrOut.OUT) {
                return I18nResources.BILL_BUFF_WITHDRAW.getI18n();
            }
        }

        //不需要处理 英文就是desc
        if (simpleDescSets.contains(bizType)) {
            return bizType.getDesc();
        }

        //处理Income Outcome的翻译。
        if (inOrOutBizTypeSets.contains(bizType)) {
            return I18nResources.valueOf(bizType.name() + "_" + inOrOut.getDescInEnglish().toUpperCase()).getI18n();
        }

        if (bizType.equals(BizType.REFUND)) {
            return StringUtils.isNotEmpty(buffBill.getBizNoRelationNo()) ? I18nResources.BILL_ORDER_REWARD_REFUND.getI18n() : I18nResources.BILL_GAME_REFUND.getI18n();

        }
        return "";
    }
}