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

import com.kamco.cd.training.model.dto.ModelTrainMngDto;
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.Size;
import java.time.ZonedDateTime;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;

@Getter
@Setter
@Entity
@Table(name = "tb_model_master")
public class ModelMasterEntity {

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

  @Column(name = "hyper_param_id")
  private Long hyperParamId;

  @Size(max = 10)
  @Column(name = "model_no", length = 10)
  private String modelNo;

  @Size(max = 200)
  @Column(name = "model_ver", length = 200)
  private String modelVer;

  @Column(name = "model_step")
  private Short modelStep;

  @Size(max = 20)
  @Column(name = "status_cd", length = 20)
  private String statusCd;

  @Column(name = "strt_dttm")
  private ZonedDateTime strtDttm;

  @Column(name = "step1_strt_dttm")
  private ZonedDateTime step1StrtDttm;

  @Column(name = "step1_end_dttm")
  private ZonedDateTime step1EndDttm;

  @Size(max = 20)
  @Column(name = "step1_state", length = 20)
  private String step1State;

  @Column(name = "step2_strt_dttm")
  private ZonedDateTime step2StrtDttm;

  @Column(name = "step2_end_dttm")
  private ZonedDateTime step2EndDttm;

  @Size(max = 20)
  @Column(name = "step2_state", length = 20)
  private String step2State;

  @Column(name = "del_yn")
  private Boolean delYn = false;

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

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

  @Column(name = "updated_dttm")
  private ZonedDateTime updatedDttm;

  @Column(name = "updated_uid")
  private Long updatedUid;

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

  @Column(name = "train_type")
  private String trainType;

  @Column(name = "before_model_id")
  private Long beforeModelId;

  @Column(name = "step1_metric_save_yn")
  private Boolean step1MetricSaveYn;

  @Column(name = "step2_metric_save_yn")
  private Boolean step2MetricSaveYn;

  @Column(name = "current_attempt_id")
  private Long currentAttemptId;

  @Column(name = "last_error")
  private String lastError;

  @Column(name = "best_epoch")
  private Integer bestEpoch;

  @Column(name = "request_path")
  private String requestPath;

  @Column(name = "response_path")
  private String responsePath;

  @Column(name = "packing_state")
  private String packingState;

  @Column(name = "packing_strt_dttm")
  private ZonedDateTime packingStrtDttm;

  @Column(name = "packing_end_dttm")
  private ZonedDateTime packingEndDttm;

  @Column(name = "req_tmp_yn")
  private Boolean reqTmpYn;

  @Column(name = "tmp_file_status")
  private String tmpFileStatus;

  @Column(name = "tmp_file_start_dttm")
  private ZonedDateTime tmpFileStartDttm;

  @Column(name = "tmp_file_end_dttm")
  private ZonedDateTime tmpFileEndDttm;

  @Column(name = "tmp_file_err_message", columnDefinition = "TEXT")
  private String tmpFileErrMessage;

  @Column(name = "before_model_uuid")
  private UUID beforeModelUuid;

  public ModelTrainMngDto.Basic toDto() {
    return new ModelTrainMngDto.Basic(
        this.id,
        this.uuid,
        this.modelVer,
        this.strtDttm,
        this.step1StrtDttm,
        this.step1EndDttm,
        this.step2StrtDttm,
        this.step2EndDttm,
        this.step1State,
        this.step2State,
        this.statusCd,
        this.trainType,
        this.modelNo,
        this.currentAttemptId,
        this.requestPath,
        this.packingState,
        this.packingStrtDttm,
        this.packingEndDttm,
        this.beforeModelId,
        this.bestEpoch,
        this.beforeModelUuid);
  }
}
