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

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

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

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

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

    @ApiModelProperty("메시지 유형 코드")  // Y VARCHAR(7)
    @Column(name = "MSG_TYPE_CD", length = 7)
    private String msgTypeCd;

    @ApiModelProperty("공통 분류 한글 명")  // Y VARCHAR(100)
    @Column(name = "CMMN_CLSF_KOR_NM", length = 100)
    private String cmmnClsfKorNm;

    @ApiModelProperty("공통 분류 영문 명")  // Y VARCHAR(100)
    @Column(name = "CMMN_CLSF_ENGL_NM", length = 100)
    private String cmmnClsfEnglNm;

    @ApiModelProperty("사용 시스템 코드")  // Y VARCHAR(7)
    @Column(name = "USE_SYST_CD", length = 7)
    private String useSystCd;

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

    @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 TbCmmnClsfCdDto toDto() {
        return TbCmmnClsfCdDto.builder()
                .cmmnClsfCd(this.cmmnClsfCd)
                .msgTypeCd(this.msgTypeCd)
                .cmmnClsfKorNm(this.cmmnClsfKorNm)
                .cmmnClsfEnglNm(this.cmmnClsfEnglNm)
                .useSystCd(this.useSystCd)
                .rmrk(this.rmrk)
                .useYn(this.useYn)
                .build();
    }

    public TbCmmnClsfCd(String cmmnClsfCd) {
        this.cmmnClsfCd = cmmnClsfCd;
    }

    public void updateInfo(TbCmmnClsfCdDto.TbCmmnClsfCdUpdReq req) {
        this.msgTypeCd = req.getMsgTypeCd();
        this.cmmnClsfKorNm = req.getCmmnClsfKorNm();
        this.cmmnClsfEnglNm = req.getCmmnClsfEnglNm();
        this.useSystCd = req.getUseSystCd();
        this.rmrk = req.getRmrk();
        this.useYn = req.getUseYn();
    }

}
