package com.bonus.core.device.manage.model;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.bonus.core.common.enums.MetadataModelTypeEnum;
import com.bonus.framework.config.deserializer.DateTimeDeserializer;
import com.bonus.framework.config.serializer.DateTimeSerializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.time.LocalDateTime;
import java.util.ArrayList;

@TableName("device_metadata")
@ApiModel("元数据配置表")
public class DeviceMetadata {
   @TableId
   @ApiModelProperty("元数据id")
   private Long metadataId;
   @ApiModelProperty("设备id")
   private Long deviceId;
   @ApiModelProperty("模型key")
   private String modelKey;
   @ApiModelProperty("模型值")
   private String modelValue;
   @ApiModelProperty("模型key备注")
   private String modelKeyRemark;
   @ApiModelProperty("创建人")
   private String crby;
   @ApiModelProperty("创建时间")
   @JsonSerialize(
      using = DateTimeSerializer.YYYY_MM_DD_HH_MM_SS.class
   )
   @JsonDeserialize(
      using = DateTimeDeserializer.class
   )
   private LocalDateTime crtime;
   @ApiModelProperty("更新人")
   private String upby;
   @ApiModelProperty("更新时间")
   @JsonSerialize(
      using = DateTimeSerializer.YYYY_MM_DD_HH_MM_SS.class
   )
   @JsonDeserialize(
      using = DateTimeDeserializer.class
   )
   private LocalDateTime uptime;

   public DeviceMetadata(Long deviceId, String modelKey, String modelValue) {
      this.deviceId = deviceId;
      this.modelKey = modelKey;
      this.modelValue = modelValue;
   }

   public String uniqueKey() {
      ArrayList<Object> keys = ListUtil.toList(new Object[]{this.deviceId, this.modelKey});
      return CollUtil.join(keys, ",");
   }

   public DeviceMetadata(MetadataModelTypeEnum modelTypeEnum, String modelKey, String modelValue, Long canteenId, Long stallId) {
      this.modelKey = modelKey;
      this.modelValue = modelValue;
   }

   public Long getMetadataId() {
      return this.metadataId;
   }

   public Long getDeviceId() {
      return this.deviceId;
   }

   public String getModelKey() {
      return this.modelKey;
   }

   public String getModelValue() {
      return this.modelValue;
   }

   public String getModelKeyRemark() {
      return this.modelKeyRemark;
   }

   public String getCrby() {
      return this.crby;
   }

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

   public String getUpby() {
      return this.upby;
   }

   public LocalDateTime getUptime() {
      return this.uptime;
   }

   public void setMetadataId(final Long metadataId) {
      this.metadataId = metadataId;
   }

   public void setDeviceId(final Long deviceId) {
      this.deviceId = deviceId;
   }

   public void setModelKey(final String modelKey) {
      this.modelKey = modelKey;
   }

   public void setModelValue(final String modelValue) {
      this.modelValue = modelValue;
   }

   public void setModelKeyRemark(final String modelKeyRemark) {
      this.modelKeyRemark = modelKeyRemark;
   }

   public void setCrby(final String crby) {
      this.crby = crby;
   }

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

   public void setUpby(final String upby) {
      this.upby = upby;
   }

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

   public DeviceMetadata() {
   }
}
