package com.its.op.entity.its.code;

import com.its.op.dto.its.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;

    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();
    }

}
