package com.crm.rely.backend.util;

import org.springframework.util.StringUtils;

public class DwTypeUtil {

    private final static Long minLogin = 60000000L;

    private final static Long maxLogin = 70000000L;

    //入金
    public final static String DEPOSIT = "DEPOSIT";
    //入金
    public final static String WITHDRAWAL = "WITHDRAWAL";
    //信用金
    public final static String CREDIT_IN = "CREDIT IN";

    public final static String CREDIT_OUT = "CREDIT OUT";
    //代理佣金内转
    public final static String AGENT_COMMISSION_TRANSFER_HEAD = "PACT";
    //入金
    public final static String DEPOSIT_HEAD = "PD";
    //出金
    public final static String WITHDRAW_HEAD = "PW";
    //出金退款
    public final static String WITHDRAW_REFUND_HEAD = "PWR";
    //代理出金
    public final static String WITHDRAW_AGENT_HEAD = "PWC";
    //内转
    public final static String TRANSFER_HEAD = "PT";
    //代理内转
    public final static String FINANCE_AGENT_TRANSFER_HEAD = "PAT";
    //异名内转
    public final static String FINANCE_SYNONYM_TRANSFER_HEAD = "PST";
    //赠金
    public final static String DEPOSIT_GIVE_HEAD = "PDG";
    //撤销信用金
    public final static String REVOKE_CREDIT_HEAD = "PRC";
    //跟单内转
    public final static String TRANSFER_FOLLOW_HEAD = "PTF";
    //免息组别持仓利息
    public final static String TRADE_INTEREST_HEAD = "PTI";
    //跟单出金(分润)
    public final static String TRADE_FOLLOW_WITHDRAW_HEAD = "PFW";
    //及时返佣 agent '1820290' - #46666030
    public final static String AGENT = "AGENT";
    //pamm账户主账户下单后分配给子账户的盈亏 from master trade #46678419
    public final static String FROM_MASTER_TRADE = "FROM MASTER TRADE";
    //销售绩效的调整
    public final static String ADJ = "ADJ";
    //销售薪资提取
    public final static String SW = "SW";
    //交易账户返现/现金嘉年华
    public final static String PTC = "PTC";
    //U卡出入金
    public final static String CARD = "CARD";
    //补零
    public final static String PCM = "PCM";

    public static Integer getDwType(Long login, String comment) throws Exception {
        if (login == null || login <= 0 || StringUtils.isEmpty(comment)) {
            return 0;
        }
        Integer type;
        if (login < minLogin && login >= maxLogin) {
            if (comment.toUpperCase().startsWith(AGENT)) {
                type = 13;
            } else {
                type = 99;
            }
        } else {
            if (comment.toUpperCase().startsWith(WITHDRAW_AGENT_HEAD)) {
                type = 2;
            } else if (comment.toUpperCase().startsWith(FINANCE_SYNONYM_TRANSFER_HEAD)) {
                type = 4;
            } else if (comment.toUpperCase().startsWith(FINANCE_AGENT_TRANSFER_HEAD)) {
                type = 5;
            } else if (comment.toUpperCase().startsWith(AGENT_COMMISSION_TRANSFER_HEAD)) {
                type = 19;
            } else if (comment.toUpperCase().startsWith(TRANSFER_FOLLOW_HEAD)) {
                type = 7;
            } else if (comment.toUpperCase().startsWith(DEPOSIT_GIVE_HEAD)) {
                type = 8;
            } else if (comment.toUpperCase().startsWith(WITHDRAW_REFUND_HEAD)) {
                type = 9;
            } else if (comment.toUpperCase().startsWith(REVOKE_CREDIT_HEAD)) {
                type = 10;
            } else if (comment.toUpperCase().startsWith(TRADE_INTEREST_HEAD)) {
                type = 11;
            } else if (comment.toUpperCase().startsWith(TRADE_FOLLOW_WITHDRAW_HEAD)) {
                type = 12;
            } else if (comment.toUpperCase().startsWith(AGENT)) {
                type = 13;
            } else if (comment.toUpperCase().startsWith(FROM_MASTER_TRADE)) {
                type = 14;
            } else if (comment.toUpperCase().startsWith(ADJ)) {
                type = 15;
            } else if (comment.toUpperCase().startsWith(SW)) {
                type = 16;
            } else if (comment.toUpperCase().startsWith(PTC)) {
                type = 17;
            } else if (comment.toUpperCase().startsWith(TRANSFER_HEAD)) {
                type = 3;
            } else if (comment.toUpperCase().startsWith(PCM)) {
                type = 20;
            } else if (comment.toUpperCase().startsWith(DEPOSIT_HEAD)
                    || comment.toUpperCase().startsWith(WITHDRAW_HEAD)
                    || comment.toUpperCase().startsWith(CREDIT_IN)
                    || comment.toUpperCase().startsWith(CREDIT_OUT)
                    || comment.toUpperCase().startsWith(CARD)) {
                type = 1;
            } else {
                type = 99;
            }

        }

        return type;
    }

}
