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

import com.kamco.cd.kamcoback.common.enums.CommonUseStatus;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.MapSheet;
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.locationtech.jts.geom.Geometry;

@Getter
@Setter
@Table(name = "tb_map_inkx_5k")
@Entity
@NoArgsConstructor
public class MapInkx5kEntity extends CommonDateEntity {

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tb_map_inkx_5k_fid_seq_gen")
  @SequenceGenerator(
      name = "tb_map_inkx_5k_fid_seq_gen",
      sequenceName = "tb_map_inkx_5k_fid_seq",
      allocationSize = 1)
  private Integer fid;

  @Column(name = "mapidcd_no")
  private String mapidcdNo;

  @Column(name = "mapid_nm")
  private String mapidNm;

  @Column(name = "geom")
  private Geometry geom;

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "fid_k50", referencedColumnName = "fid")
  private MapInkx50kEntity mapInkx50k;

  // 사용상태 USE,
  @Column(name = "use_inference")
  @Enumerated(EnumType.STRING)
  private CommonUseStatus useInference;

  // Constructor
  public MapInkx5kEntity(
      String mapidcdNo, String mapidNm, Geometry geom, MapInkx50kEntity mapInkx50k) {
    this.mapidcdNo = mapidcdNo;
    this.mapidNm = mapidNm;
    this.geom = geom;
    this.mapInkx50k = mapInkx50k;
    // 생성시 default 사용함  (사용,제외,사용안함)
    this.useInference = CommonUseStatus.USE;
  }

  // 변경 사용상태 (추론사용여부)
  public void updateUseInference(CommonUseStatus useInference) {
    this.useInference = useInference;
  }

  public InferenceResultDto.MapSheet toEntity() {
    return new MapSheet(mapidcdNo, mapidNm);
  }
}
