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

import com.its.api.its.model.dto.facility.TbFcltInfrDto;
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_FCLT_INFR")
public class TbFcltInfr implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("시설물 ID")  // N VARCHAR(50)
    @Id
    @Column(name = "FCLT_ID", nullable = false, length = 50)
    private String fcltId;

    @ApiModelProperty("시설물 유형")  // Y VARCHAR(7)
    @Column(name = "FCLT_TYPE", length = 7)
    private String fcltType;

    @ApiModelProperty("시설물 위치")  // Y VARCHAR(100)
    @Column(name = "FCLT_LCTN", length = 100)
    private String fcltLctn;

    @ApiModelProperty("설치 위치 주소")  // Y VARCHAR(200)
    @Column(name = "ISTL_LCTN_ADDR", length = 200)
    private String istlLctnAddr;

    @ApiModelProperty("자산 유무")  // Y CHAR(1)
    @Column(name = "RSCE_YN", columnDefinition = "CHAR", length = 1)
    private String rsceYn;

    @ApiModelProperty("모델 명")  // Y VARCHAR(30)
    @Column(name = "MDL_NM", length = 30)
    private String mdlNm;

    @ApiModelProperty("사용 년수")  // Y NUMBER(3)
    @Column(name = "USE_YEAR", columnDefinition = "NUMBER", length = 3)
    private Integer useYear;

    @ApiModelProperty("입고 일시")  // Y VARCHAR(14)
    @Column(name = "INWR_DT", length = 14)
    private String inwrDt;

    @ApiModelProperty("출고 일시")  // Y VARCHAR(14)
    @Column(name = "OTWR_DT", length = 14)
    private String otwrDt;

    @ApiModelProperty("설치 일시")  // Y VARCHAR(14)
    @Column(name = "ISTL_DT", length = 14)
    private String istlDt;

    @ApiModelProperty("반출 일시")  // Y VARCHAR(14)
    @Column(name = "TAKT_DT", length = 14)
    private String taktDt;

    @ApiModelProperty("반출 사유")  // Y VARCHAR(100)
    @Column(name = "TAKT_RESN", length = 100)
    private String taktResn;

    @ApiModelProperty("반입 일시")  // Y VARCHAR(14)
    @Column(name = "TAKN_DT", length = 14)
    private String taknDt;

    @ApiModelProperty("폐기 일시")  // Y VARCHAR(14)
    @Column(name = "ABDN_DT", length = 14)
    private String abdnDt;

    @ApiModelProperty("추가자 명")  // Y VARCHAR(30)
    @Column(name = "ADTN_NM", length = 30)
    private String adtnNm;

    @ApiModelProperty("추가 일시")  // Y VARCHAR(14)
    @Column(name = "ADTN_DT", length = 14)
    private String adtnDt;

    @ApiModelProperty("변경자 명")  // Y VARCHAR(30)
    @Column(name = "CHNG_NM", length = 30)
    private String chngNm;

    @ApiModelProperty("변경 일시")  // Y VARCHAR(14)
    @Column(name = "CHNG_DT", length = 14)
    private String chngDt;

    @ApiModelProperty("금액")  // Y NUMBER(15)
    @Column(name = "AMT", columnDefinition = "NUMBER", length = 15)
    private Long amt;

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

    @ApiModelProperty("설치 업체 ID")  // Y VARCHAR(30)
    @Column(name = "ISTL_CMPY_ID", length = 30)
    private String istlCmpyId;

    @ApiModelProperty("제조 업체 ID")  // Y VARCHAR(30)
    @Column(name = "MNFC_CMPY_ID", length = 30)
    private String mnfcCmpyId;

    @ApiModelProperty("RFID ID")  // Y VARCHAR(30)
    @Column(name = "RFID_ID", length = 30)
    private String rfidId;

    public TbFcltInfrDto toDto() {
        return TbFcltInfrDto.builder()
                .fcltId(this.fcltId)
                .fcltType(this.fcltType)
                .fcltLctn(this.fcltLctn)
                .istlLctnAddr(this.istlLctnAddr)
                .rsceYn(this.rsceYn)
                .mdlNm(this.mdlNm)
                .useYear(this.useYear)
                .inwrDt(this.inwrDt)
                .otwrDt(this.otwrDt)
                .istlDt(this.istlDt)
                .taktDt(this.taktDt)
                .taktResn(this.taktResn)
                .taknDt(this.taknDt)
                .abdnDt(this.abdnDt)
                .adtnNm(this.adtnNm)
                .adtnDt(this.adtnDt)
                .chngNm(this.chngNm)
                .chngDt(this.chngDt)
                .amt(this.amt)
                .delYn(this.delYn)
                .istlCmpyId(this.istlCmpyId)
                .mnfcCmpyId(this.mnfcCmpyId)
                .rfidId(this.rfidId)
                .build();
    }

    public TbFcltInfr(String fcltId) {
        this.fcltId = fcltId;
    }

    public void updateInfo(TbFcltInfrDto.TbFcltInfrUpdReq req) {
        this.fcltType = req.getFcltType();
        this.fcltLctn = req.getFcltLctn();
        this.istlLctnAddr = req.getIstlLctnAddr();
        this.rsceYn = req.getRsceYn();
        this.mdlNm = req.getMdlNm();
        this.useYear = req.getUseYear();
        this.inwrDt = req.getInwrDt();
        this.otwrDt = req.getOtwrDt();
        this.istlDt = req.getIstlDt();
        this.taktDt = req.getTaktDt();
        this.taktResn = req.getTaktResn();
        this.taknDt = req.getTaknDt();
        this.abdnDt = req.getAbdnDt();
        this.adtnNm = req.getAdtnNm();
        this.adtnDt = req.getAdtnDt();
        this.chngNm = req.getChngNm();
        this.chngDt = req.getChngDt();
        this.amt = req.getAmt();
        this.delYn = req.getDelYn();
        this.istlCmpyId = req.getIstlCmpyId();
        this.mnfcCmpyId = req.getMnfcCmpyId();
        this.rfidId = req.getRfidId();
    }

}
