package com.bonus.core.account.v4.app.vo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.bonus.core.account.v3.constants.AccTradeTypeEnum;
import com.bonus.core.account.v3.model.AccTradeWalletDetail;
import io.swagger.annotations.ApiModelProperty;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;

public class AppSubsidyTradeVO {
   @ApiModelProperty("交易类型")
   private Integer tradeType;
   @ApiModelProperty("交易类型名称")
   private String tradeTypeName;
   @ApiModelProperty("交易金额/分")
   private BigDecimal amount;
   @ApiModelProperty("交易金额(展示元)")
   private String amountTitle;
   @ApiModelProperty("交易时间")
   private LocalDateTime tradeTime;
   @ApiModelProperty("补贴有效期")
   private LocalDateTime validityTime;
   @ApiModelProperty("补贴有效期(展示)")
   private String validityTimeTitle;

   public static AppSubsidyTradeVO of(AccTradeWalletDetail walletDetail) {
      AppSubsidyTradeVO appSubsidyTradeVO = new AppSubsidyTradeVO();
      appSubsidyTradeVO.setTradeType(walletDetail.getTradeType());
      appSubsidyTradeVO.setTradeTypeName(AccTradeTypeEnum.getDesc(walletDetail.getTradeType()));
      appSubsidyTradeVO.setAmount(ObjectUtil.isNull(walletDetail.getAmount()) ? BigDecimal.ZERO : walletDetail.getAmount());
      appSubsidyTradeVO.setTradeTime(walletDetail.getTradeTime());
      if (ObjectUtil.isNotNull(walletDetail.getValidateTime())) {
         appSubsidyTradeVO.setValidityTime(walletDetail.getValidateTime());
         String format = DateUtil.format(walletDetail.getValidateTime(), "yyyy-MM-dd");
         appSubsidyTradeVO.setValidityTimeTitle("有效期至" + format);
      }

      BigDecimal amountYuan = appSubsidyTradeVO.getAmount().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
      String amountStr;
      if (AccTradeTypeEnum.subIncomeTypeList().contains(walletDetail.getTradeType())) {
         amountStr = "+" + String.valueOf(amountYuan);
      } else {
         amountStr = "-" + String.valueOf(amountYuan);
      }

      appSubsidyTradeVO.setAmountTitle(amountStr);
      return appSubsidyTradeVO;
   }

   public Integer getTradeType() {
      return this.tradeType;
   }

   public String getTradeTypeName() {
      return this.tradeTypeName;
   }

   public BigDecimal getAmount() {
      return this.amount;
   }

   public String getAmountTitle() {
      return this.amountTitle;
   }

   public LocalDateTime getTradeTime() {
      return this.tradeTime;
   }

   public LocalDateTime getValidityTime() {
      return this.validityTime;
   }

   public String getValidityTimeTitle() {
      return this.validityTimeTitle;
   }

   public void setTradeType(final Integer tradeType) {
      this.tradeType = tradeType;
   }

   public void setTradeTypeName(final String tradeTypeName) {
      this.tradeTypeName = tradeTypeName;
   }

   public void setAmount(final BigDecimal amount) {
      this.amount = amount;
   }

   public void setAmountTitle(final String amountTitle) {
      this.amountTitle = amountTitle;
   }

   public void setTradeTime(final LocalDateTime tradeTime) {
      this.tradeTime = tradeTime;
   }

   public void setValidityTime(final LocalDateTime validityTime) {
      this.validityTime = validityTime;
   }

   public void setValidityTimeTitle(final String validityTimeTitle) {
      this.validityTimeTitle = validityTimeTitle;
   }

}
