package com.dbnt.kcscopensearch.opensearch.documentGroup.model;

import com.dbnt.kcscopensearch.kcsc.tnDocumentGroup.model.TnDocumentGroup;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

@Getter
@Setter
@NoArgsConstructor
@Document(indexName = "document_group")
public class DocumentGroup {

  @Id
  private Integer id;

  @Field(type = FieldType.Integer, name = "group_seq")
  private Integer groupSeq;
  @Field(type = FieldType.Text, name = "group_full_cd")
  private String groupFullCd;
  @Field(type = FieldType.Text, name = "kcsc_cd")
  private String kcscCd;
  @Field(type = FieldType.Text, name = "group_cur_cd")
  private String groupCurCd;
  @Field(type = FieldType.Text, name = "group_nm")
  private String groupNm;
  @Field(type = FieldType.Text, name = "group_type")
  private String groupType;
  @Field(type = FieldType.Text, name = "item_cd")
  private String itemCd;
  @Field(type = FieldType.Integer, name = "doc_type")
  private Integer docType;
  @Field(type = FieldType.Integer, name = "doc_level")
  private Integer docLevel;
  @Field(type = FieldType.Integer, name = "doc_order")
  private Integer docOrder;
  @Field(type = FieldType.Integer, name = "parent_group_seq")
  private Integer parentGroupSeq;
  @Field(type = FieldType.Text, name = "rvsn_remark")
  private String rvsnRemark;
  @Field(type = FieldType.Text, name = "frst_crt_id")
  private String frstCrtId;
  @Field(type = FieldType.Date, name = "frst_crt_dt")
  @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS")
  @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", timezone = "Asia/Seoul")
  private LocalDateTime frstCrtDt;
  @Field(type = FieldType.Text, name = "last_chg_id")
  private String lastChgId;
  @Field(type = FieldType.Date, name = "last_chg_dt")
  @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS")
  @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", timezone = "Asia/Seoul")
  private LocalDateTime lastChgDt;
  @Field(type = FieldType.Text, name = "use_yn")
  private String useYn;
  @Field(type = FieldType.Integer, name = "old_seq")
  private Integer oldSeq;

  public DocumentGroup(TnDocumentGroup documentGroup){
    this.id = documentGroup.getGroupSeq();
    this.groupSeq = documentGroup.getGroupSeq();
    this.groupFullCd = documentGroup.getGroupCurCd();
    this.kcscCd = documentGroup.getKcscCd();
    this.groupCurCd = documentGroup.getGroupCurCd();
    this.groupNm = documentGroup.getGroupNm();
    this.groupType = documentGroup.getGroupNm();
    this.itemCd = documentGroup.getItemCd();
    this.docType = documentGroup.getDocType();
    this.docLevel = documentGroup.getDocLevel();
    this.docOrder = documentGroup.getDocOrder();
    this.parentGroupSeq = documentGroup.getParentGroupSeq();
    this.rvsnRemark = documentGroup.getRvsnRemark();
    this.frstCrtId = documentGroup.getFrstCrtId();
    this.frstCrtDt = documentGroup.getFrstCrtDt();
    this.lastChgId = documentGroup.getLastChgId();
    this.lastChgDt = documentGroup.getLastChgDt();
    this.useYn = documentGroup.getUseYn();
    this.oldSeq = documentGroup.getOldSeq();
  }
}
