package com.kamco.cd.training.postgres.entity;

import com.kamco.cd.training.dataset.dto.DatasetObjDto.Basic;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.ZonedDateTime;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;
import org.locationtech.jts.geom.Geometry;

@Getter
@Setter
@Entity
@Table(name = "tb_dataset_test_obj")
public class DatasetTestObjEntity {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "obj_id", nullable = false)
  private Long objId;

  @NotNull
  @Column(name = "dataset_uid", nullable = false)
  private Long datasetUid;

  @Column(name = "target_yyyy")
  private Integer targetYyyy;

  @Size(max = 255)
  @Column(name = "target_class_cd")
  private String targetClassCd;

  @Column(name = "compare_yyyy")
  private Integer compareYyyy;

  @Size(max = 255)
  @Column(name = "compare_class_cd")
  private String compareClassCd;

  @Size(max = 255)
  @Column(name = "target_path")
  private String targetPath;

  @Size(max = 255)
  @Column(name = "compare_path")
  private String comparePath;

  @Size(max = 255)
  @Column(name = "label_path")
  private String labelPath;

  @Size(max = 255)
  @Column(name = "geojson_path")
  private String geojsonPath;

  @Size(max = 255)
  @Column(name = "map_sheet_num")
  private String mapSheetNum;

  @ColumnDefault("now()")
  @Column(name = "created_dttm")
  private ZonedDateTime createdDttm;

  @Column(name = "created_uid")
  private Long createdUid;

  @ColumnDefault("false")
  @Column(name = "deleted")
  private Boolean deleted;

  @Column(name = "uuid")
  private UUID uuid;

  @Size(max = 32)
  @Column(name = "uid")
  private String uid;

  @JdbcTypeCode(SqlTypes.JSON)
  @Column(name = "geo_jsonb", columnDefinition = "jsonb")
  private String geoJsonb;

  @Column(name = "file_name")
  private String fileName;

  @Column(name = "geom", columnDefinition = "geometry")
  private Geometry geom;

  public Basic toDto() {
    return new Basic(
        this.objId,
        this.datasetUid,
        this.targetYyyy,
        this.targetClassCd,
        this.compareYyyy,
        this.compareClassCd,
        this.targetPath,
        this.comparePath,
        this.labelPath,
        this.geojsonPath,
        this.mapSheetNum,
        this.createdDttm,
        this.createdUid,
        this.deleted,
        this.uuid,
        this.geoJsonb);
  }
}
