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

import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;

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

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tb_model_mng_id_gen")
  @SequenceGenerator(
      name = "tb_model_mng_id_gen",
      sequenceName = "tb_model_mng_model_uid",
      allocationSize = 1)
  @Column(name = "model_uid", nullable = false)
  private Long id;

  @Size(max = 100)
  @ColumnDefault("'NULL::character varying'")
  @Column(name = "model_nm", length = 100)
  private String modelNm;

  @Size(max = 64)
  @ColumnDefault("'NULL::character varying'")
  @Column(name = "model_cate", length = 64)
  private String modelCate;

  @Size(max = 255)
  @ColumnDefault("'NULL::character varying'")
  @Column(name = "model_path")
  private String modelPath;

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

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

  @Column(name = "model_cntnt", columnDefinition = "TEXT")
  private String modelCntnt;

  @Column(name = "bbone_ver")
  private String bboneVer;

  public ModelMngEntity(
      String modelNm,
      String modelCate,
      String modelPath,
      Long createdUid,
      Long updatedUid,
      String modelCntnt) {
    this.modelNm = modelNm;
    this.modelCate = modelCate;
    this.modelPath = modelPath;
    this.modelCntnt = modelCntnt;

    this.createdUid = createdUid;
    this.updatedUid = updatedUid;
  }

  public ModelMngDto.Basic toDto() {
    return new ModelMngDto.Basic(
        this.id,
        this.modelNm,
        this.modelCate,
        this.modelPath,
        super.getCreatedDate(),
        this.createdUid,
        super.getModifiedDate(),
        this.updatedUid,
        this.modelCntnt);
  }
}
