package com.sonic.lion.domain.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.sonic.lion.enums.BizType;
import com.sonic.lion.domain.enums.*;
import com.sonic.lion.enums.PayChannel;
import com.sonic.lion.enums.I18nResources;
import lombok.*;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * account_buff_bill
 *
 * @author
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "account_buff_bill", autoResultMap = true)
public class AccountBuffBill implements Serializable {

    @TableId(type = IdType.AUTO)
    private Long id;

    private String platform;

    private String billNo;

    private Long accountId;

    private Long uid;

    private Long desUid;

    /**
     * 游戏订单 担保交易 冗余目标方的用户id
     */
    private Long targetUserId;

    private Long buff;

    /**
     * Buff 归类
     */
    private BuffClassifyEnum buffClassify;

    /**
     * 赠送金额
     */
    private Long giftAmount;

    private BizType bizType;

    private PayChannel payChannel;

    private String tradeNo;

    private String bizNo;

    private String payMethod;

    /**
     * 外部交易号关联单号（如：打赏单号关联的游戏订单的订单号）
     */
    private String bizNoRelationNo;

    private Long balance;

    private InOrOut inOrOut;

    private BuffType buffType;

    /**
     * 转入可提现收入时间
     */
    private LocalDateTime toWithdrawableIncomeTime;

    private LocalDateTime createTime;

    private LocalDateTime editTime;


    private BillStatusEnum billStatus;

    /**
     * 提现状态
     */
    private WithdrawStatus withdrawStatus;

    private String reason;

    private String extend;

    @TableLogic
    @TableField("is_deleted")
    private Boolean deleted;

    private static final long serialVersionUID = 1L;

    /**
     * 提现状态
     */
    @AllArgsConstructor
    @Getter
    public enum WithdrawStatus {
        //审核中
        IN_REVIEW("review"),
        //审核失败
        REVIEW_FAIL("review failed"),
        //提现中
        WITHDRAW_ING("processing"),
        //提现失败
        WITHDRAW_FAIL("failed"),
        WITHDRAW_SUCCESS("success"),
        //提现失败返还
        WITHDRAW_FAIL_BACK("failed back"),
        ;
        private String status;

    }

    public String getStatus() {
        if (BuffType.AWAITING_INCOME.equals(buffType) && InOrOut.IN.equals(inOrOut)) {
            //为待入帐状态
            return I18nResources.AWAITING_INCOME_STATUS.getI18n();
        }
        if (BizType.WITHDRAW.equals(bizType) && withdrawStatus != null && !WithdrawStatus.WITHDRAW_FAIL_BACK.equals(withdrawStatus)) {
            return I18nResources.valueOf(withdrawStatus.name()).getI18n();
        }
        return I18nResources.WITHDRAW_SUCCESS.getI18n();
    }


    /**
     * 前端界面 优先显示 支付方式.
     *
     * @return
     */
    public String getPayment() {
        if (StringUtils.isNotBlank(payMethod)) {
            if ("sofort".equals(payMethod)) {
                return "Sofort";
            }
            if ("giropay_de".equals(payMethod)) {
                return "Giropay";
            }
            return payMethod;
        }
        return payChannel.getDesc();
    }
}