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

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

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

}
