package com.its.api.its.model.entity.code;

import com.its.api.its.model.dto.code.TbCmmnCdDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.*;
import java.io.Serializable;

/**
 * 공통 코드 Entity Class
 */
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("공통 코드")
@Entity
@Table(name = "TB_CMMN_CD")
@IdClass(TbCmmnCdKey.class)
public class TbCmmnCd implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("공통 코드")  // N VARCHAR(7)
    @Id
    @Column(name = "CMMN_CD", nullable = false, length = 7)
    private String cmmnCd;

    @ApiModelProperty("공통 분류 코드")  // N VARCHAR(5)
    @Id
    @Column(name = "CMMN_CLSF_CD", nullable = false, length = 5)
    private String cmmnClsfCd;

    @ApiModelProperty("공통 코드 한글 명")  // Y VARCHAR(100)
    @Column(name = "CMMN_CD_KOR_NM", length = 100)
    private String cmmnCdKorNm;

    @ApiModelProperty("공통 코드 영문 명")  // Y VARCHAR(100)
    @Column(name = "CMMN_CD_ENGL_NM", length = 100)
    private String cmmnCdEnglNm;

    @ApiModelProperty("공통 코드 약어")  // Y VARCHAR(40)
    @Column(name = "CMMN_CD_ABBR", length = 40)
    private String cmmnCdAbbr;

    @ApiModelProperty("비고")  // Y VARCHAR(600)
    @Column(name = "RMRK", length = 600)
    private String rmrk;

    @ApiModelProperty("속성1")  // Y VARCHAR(60)
    @Column(name = "ATRB1", length = 60)
    private String atrb1;

    @ApiModelProperty("속성2")  // Y VARCHAR(60)
    @Column(name = "ATRB2", length = 60)
    private String atrb2;

    @ApiModelProperty("사용 여부")  // Y CHAR(1)
    @Column(name = "USE_YN", columnDefinition = "CHAR", length = 1)
    private String useYn;

    @ApiModelProperty("최초 등록자 번호")  // Y VARCHAR(20)
    @Column(name = "FRST_REGR_NMBR", length = 20)
    private String frstRegrNmbr;

    @ApiModelProperty("최초 등록 일시")  // Y VARCHAR(14)
    @Column(name = "FRST_RGST_DT", length = 14)
    private String frstRgstDt;

    @ApiModelProperty("최종 수정자 번호")  // Y VARCHAR(20)
    @Column(name = "LAST_CRPR_NMBR", length = 20)
    private String lastCrprNmbr;

    @ApiModelProperty("최종 수정 일시")  // Y VARCHAR(14)
    @Column(name = "LAST_CRCT_DT", length = 14)
    private String lastCrctDt;

    public TbCmmnCdDto toDto() {
        return TbCmmnCdDto.builder()
                .cmmnCd(this.cmmnCd)
                .cmmnClsfCd(this.cmmnClsfCd)
                .cmmnCdKorNm(this.cmmnCdKorNm)
                .cmmnCdEnglNm(this.cmmnCdEnglNm)
                .cmmnCdAbbr(this.cmmnCdAbbr)
                .rmrk(this.rmrk)
                .atrb1(this.atrb1)
                .atrb2(this.atrb2)
                .useYn(this.useYn)
                .frstRegrNmbr(this.frstRegrNmbr)
                .frstRgstDt(this.frstRgstDt)
                .lastCrprNmbr(this.lastCrprNmbr)
                .lastCrctDt(this.lastCrctDt)
                .build();
    }

    public TbCmmnCd(String cmmnCd, String cmmnClsfCd) {
        this.cmmnCd = cmmnCd;
        this.cmmnClsfCd = cmmnClsfCd;
    }

    public void updateInfo(TbCmmnCdDto.TbCmmnCdUpdReq req) {
        this.cmmnCdKorNm = req.getCmmnCdKorNm();
        this.cmmnCdEnglNm = req.getCmmnCdEnglNm();
        this.cmmnCdAbbr = req.getCmmnCdAbbr();
        this.rmrk = req.getRmrk();
        this.atrb1 = req.getAtrb1();
        this.atrb2 = req.getAtrb2();
        this.useYn = req.getUseYn();
        this.frstRegrNmbr = req.getFrstRegrNmbr();
        this.frstRgstDt = req.getFrstRgstDt();
        this.lastCrprNmbr = req.getLastCrprNmbr();
        this.lastCrctDt = req.getLastCrctDt();
    }

}
