package com.bonus.core.order.mq;

import com.bonus.core.common.constant.LeMqConstant;
import com.bonus.framework.config.deserializer.DateTimeDeserializer;
import com.bonus.framework.config.serializer.DateTimeSerializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModelProperty;

import java.time.LocalDateTime;

public class MqDataChangeMessageDto {
   @ApiModelProperty("商户")
   private Long tenantId;
   @ApiModelProperty("变更数据")
   private JsonNode data;
   @ApiModelProperty("数据更新类型")
   private LeMqConstant.DataChangeType changeType;
   @ApiModelProperty("数据更新主题")
   private LeMqConstant.Topic changeTopic;
   @JsonSerialize(
      using = DateTimeSerializer.YYYY_MM_DD_HH_MM_SS.class
   )
   @JsonDeserialize(
      using = DateTimeDeserializer.class
   )
   @ApiModelProperty("发送时间")
   private LocalDateTime sendTime;
   @ApiModelProperty("用户")
   private String userName;
   @ApiModelProperty("操作员id")
   private Long userId;

   public Long getTenantId() {
      return this.tenantId;
   }

   public JsonNode getData() {
      return this.data;
   }

   public LeMqConstant.DataChangeType getChangeType() {
      return this.changeType;
   }

   public LeMqConstant.Topic getChangeTopic() {
      return this.changeTopic;
   }

   public LocalDateTime getSendTime() {
      return this.sendTime;
   }

   public String getUserName() {
      return this.userName;
   }

   public Long getUserId() {
      return this.userId;
   }

   public void setTenantId(final Long tenantId) {
      this.tenantId = tenantId;
   }

   public void setData(final JsonNode data) {
      this.data = data;
   }

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

   public void setChangeTopic(final LeMqConstant.Topic changeTopic) {
      this.changeTopic = changeTopic;
   }

   @JsonDeserialize(
      using = DateTimeDeserializer.class
   )
   public void setSendTime(final LocalDateTime sendTime) {
      this.sendTime = sendTime;
   }

   public void setUserName(final String userName) {
      this.userName = userName;
   }

   public void setUserId(final Long userId) {
      this.userId = userId;
   }


   public MqDataChangeMessageDto() {
   }

   private MqDataChangeMessageDto(final Long tenantId, final JsonNode data, final LeMqConstant.DataChangeType changeType, final LeMqConstant.Topic changeTopic, final LocalDateTime sendTime, final String userName, final Long userId) {
      this.tenantId = tenantId;
      this.data = data;
      this.changeType = changeType;
      this.changeTopic = changeTopic;
      this.sendTime = sendTime;
      this.userName = userName;
      this.userId = userId;
   }

   public static MqDataChangeMessageDto of(final Long tenantId, final JsonNode data, final LeMqConstant.DataChangeType changeType, final LeMqConstant.Topic changeTopic, final LocalDateTime sendTime, final String userName, final Long userId) {
      return new MqDataChangeMessageDto(tenantId, data, changeType, changeTopic, sendTime, userName, userId);
   }
}
