package com.bonus.core.order.common.model;

import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.bonus.core.order.common.constants.ChangeDetailTypeEnum;
import com.bonus.core.order.common.constants.ChangeTypeEnum;
import com.bonus.utils.id.Id;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;

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

@TableName("order_amount_change")
public class OrderAmountChange {
   private Long changeId;
   @DateTimeFormat(
      pattern = "yyyy-MM-dd"
   )
   @JsonFormat(
      pattern = "yyyy-MM-dd"
   )
   private LocalDate orderDate;
   private Long orderId;
   private BigDecimal changeAmount;
   private Integer changeType;
   private Integer changeDetailType;
   private String remark;
   @DateTimeFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   private LocalDateTime crtime;

   public static OrderAmountChange newInstance(Long orderId, LocalDate orderDate, ChangeDetailTypeEnum detailTypeEnum, BigDecimal changeAmount, String remark) {
      OrderAmountChange orderAmountChange = new OrderAmountChange();
      orderAmountChange.setChangeId(Id.next());
      orderAmountChange.setOrderId(orderId);
      orderAmountChange.setOrderDate(orderDate);
      orderAmountChange.setChangeAmount(changeAmount);
      orderAmountChange.setChangeType(NumberUtil.isGreater(changeAmount, BigDecimal.ZERO) ? ChangeTypeEnum.DISCOUNTS.getKey() : ChangeTypeEnum.COME_UP.getKey());
      orderAmountChange.setChangeDetailType(detailTypeEnum.getKey());
      orderAmountChange.setRemark(remark);
      return orderAmountChange;
   }

   public static String[] logFields() {
      return new String[]{"changeId", "orderId", "changeAmount", "changeType", "changeDetailType"};
   }

   public Long getChangeId() {
      return this.changeId;
   }

   public LocalDate getOrderDate() {
      return this.orderDate;
   }

   public Long getOrderId() {
      return this.orderId;
   }

   public BigDecimal getChangeAmount() {
      return this.changeAmount;
   }

   public Integer getChangeType() {
      return this.changeType;
   }

   public Integer getChangeDetailType() {
      return this.changeDetailType;
   }

   public String getRemark() {
      return this.remark;
   }

   public LocalDateTime getCrtime() {
      return this.crtime;
   }

   public void setChangeId(final Long changeId) {
      this.changeId = changeId;
   }

   @JsonFormat(
      pattern = "yyyy-MM-dd"
   )
   public void setOrderDate(final LocalDate orderDate) {
      this.orderDate = orderDate;
   }

   public void setOrderId(final Long orderId) {
      this.orderId = orderId;
   }

   public void setChangeAmount(final BigDecimal changeAmount) {
      this.changeAmount = changeAmount;
   }

   public void setChangeType(final Integer changeType) {
      this.changeType = changeType;
   }

   public void setChangeDetailType(final Integer changeDetailType) {
      this.changeDetailType = changeDetailType;
   }

   public void setRemark(final String remark) {
      this.remark = remark;
   }

   @JsonFormat(
      pattern = "yyyy-MM-dd HH:mm:ss"
   )
   public void setCrtime(final LocalDateTime crtime) {
      this.crtime = crtime;
   }

}
