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

import com.its.api.its.global.CodeManager;
import com.its.api.its.model.dto.database.TbCnctIntnDto;
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_CNCT_INTN")
public class TbCnctIntn implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("연계 기관 관리 번호")  // N NUMBER(10)
    @Id
    @Column(name = "CNCT_INTN_MNGM_NMBR", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long cnctIntnMngmNmbr;

    @ApiModelProperty("연계 기관 명")  // Y VARCHAR(50)
    @Column(name = "CNCT_INTN_NM", length = 50)
    private String cnctIntnNm;

    @ApiModelProperty("연계 기관 유형 코드")  // Y VARCHAR(7)
    @Column(name = "CNCT_INTN_TYPE_CD", length = 7)
    private String cnctIntnTypeCd;

    @ApiModelProperty("연계 기관 전화번호")  // Y VARCHAR(128)
    @Column(name = "CNCT_INTN_TEL", length = 128)
    private String cnctIntnTel;

    @ApiModelProperty("연계 기관 주소")  // Y VARCHAR(200)
    @Column(name = "CNCT_INTN_ADDR", length = 200)
    private String cnctIntnAddr;

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

    @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;

    @ApiModelProperty("삭제 여부")  // Y CHAR(1)
    @Column(name = "DEL_YN", columnDefinition = "CHAR", length = 1)
    private String delYn;

    public TbCnctIntnDto toDto() {
        TbCnctIntnDto dto = TbCnctIntnDto.builder()
                .cnctIntnMngmNmbr(this.cnctIntnMngmNmbr)
                .cnctIntnNm(this.cnctIntnNm)
                .cnctIntnTypeCd(this.cnctIntnTypeCd)
                .cnctIntnTel(this.cnctIntnTel)
                .cnctIntnAddr(this.cnctIntnAddr)
                .rmrk(this.rmrk)
                .delYn(this.delYn)
                .build();

        dto.setCnctIntnTypeDesc(CodeManager.getCodeDesc(CodeManager.CNCT_INTN_TYPE_CD, this.getCnctIntnTypeCd()));

        return dto;
    }

    public TbCnctIntn(Long cnctIntnMngmNmbr) {
        this.cnctIntnMngmNmbr = cnctIntnMngmNmbr;
    }

    public void updateInfo(TbCnctIntnDto.TbCnctIntnUpdReq req) {
        this.cnctIntnNm = req.getCnctIntnNm();
        this.cnctIntnTypeCd = req.getCnctIntnTypeCd();
        this.cnctIntnTel = req.getCnctIntnTel();
        this.cnctIntnAddr = req.getCnctIntnAddr();
        this.rmrk = req.getRmrk();
        this.delYn = req.getDelYn();
    }

}
