package com.its.op.entity.its.rse;

import com.its.op.dto.its.rse.TbRseCtlrDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

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

/**
 * RSE 마스터 정보 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("RSE 마스터 정보")
@Entity
@Table(name = "TB_RSE_CTLR")
public class TbRseCtlr implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("RSE 제어기 번호")  // N NUMBER(10)
    @Id
    @Column(name = "RSE_CTLR_NMBR", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long rseCtlrNmbr;

    @ApiModelProperty("RSE 제어기 ID")  // Y VARCHAR2(30)
    @Column(name = "RSE_CTLR_ID", length = 30)
    private String rseCtlrId;

    @ApiModelProperty("RSE 명칭")  // Y VARCHAR2(40)
    @Column(name = "RSE_NM", length = 40)
    private String rseNm;

    @ApiModelProperty("RSE 제어기 아이피")  // Y VARCHAR2(20)
    @Column(name = "RSE_CTLR_IP", length = 20)
    private String rseCtlrIp;

    @ApiModelProperty("RSE 제어기 포트")  // Y NUMBER(5)
    @Column(name = "RSE_CTLR_PORT", columnDefinition = "NUMBER", length = 5)
    private Integer rseCtlrPort;

    @ApiModelProperty("RSE 제어기 지역번호")  // Y NUMBER(5)
    @Column(name = "RSE_CTLR_LOCAL_NO", columnDefinition = "NUMBER", length = 5)
    private Integer rseCtlrLocalNo;

    @ApiModelProperty("RSE 유형 코드('RSET')")  // Y VARCHAR2(7)
    @Column(name = "RSE_TYPE_CD", length = 7)
    private String rseTypeCd;

    @ApiModelProperty("설치 위치 명")  // Y VARCHAR2(40)
    @Column(name = "ISTL_LCTN_NM", length = 40)
    private String istlLctnNm;

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

    @ApiModelProperty("X 좌표")  // Y NUMBER(11,8)
    @Column(name = "X_CRDN", columnDefinition = "NUMBER", length = 11, precision = 8)
    private Double xCrdn;

    @ApiModelProperty("Y 좌표")  // Y NUMBER(10,8)
    @Column(name = "Y_CRDN", columnDefinition = "NUMBER", length = 10, precision = 8)
    private Double yCrdn;

    @ApiModelProperty("MCU ID")  // Y VARCHAR2(30)
    @Column(name = "RSE_MCU_ID", length = 30)
    private String rseMcuId;

    @ApiModelProperty("로그 접속 아이디")  // Y VARCHAR2(64)
    @Column(name = "LOG_CNNC_ID", length = 64)
    private String logCnncId;

    @ApiModelProperty("로그 접속 비밀번호")  // Y VARCHAR2(64)
    @Column(name = "LOG_CNNC_PW", length = 64)
    private String logCnncPw;

    @ApiModelProperty("제조 업체 코드")  // Y NUMBER(5)
    @Column(name = "MNFC_CMPY_CD", columnDefinition = "NUMBER", length = 5)
    private Integer mnfcCmpyCd;

    @ApiModelProperty("수집 이상 기준")  // Y NUMBER(7)
    @Column(name = "CLCT_ABNR_BASI", columnDefinition = "NUMBER", length = 7)
    private Integer clctAbnrBasi;

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

    public TbRseCtlrDto toDto() {
        return TbRseCtlrDto.builder()
                .rseCtlrNmbr(this.rseCtlrNmbr)
                .rseCtlrId(this.rseCtlrId)
                .rseNm(this.rseNm)
                .rseCtlrIp(this.rseCtlrIp)
                .rseCtlrPort(this.rseCtlrPort)
                .rseCtlrLocalNo(this.rseCtlrLocalNo)
                .rseTypeCd(this.rseTypeCd)
                .istlLctnNm(this.istlLctnNm)
                .istlLctnAddr(this.istlLctnAddr)
                .xCrdn(this.xCrdn)
                .yCrdn(this.yCrdn)
                .rseMcuId(this.rseMcuId)
                .logCnncId(this.logCnncId)
                .logCnncPw(this.logCnncPw)
                .mnfcCmpyCd(this.mnfcCmpyCd)
                .clctAbnrBasi(this.clctAbnrBasi)
                .delYn(this.delYn)
                .build();
    }

    public TbRseCtlr(Long rseCtlrNmbr) {
        this.rseCtlrNmbr = rseCtlrNmbr;
    }

    public void updateInfo(TbRseCtlrDto.TbRseCtlrUpdReq req) {
        this.rseCtlrId = req.getRseCtlrId();
        this.rseNm = req.getRseNm();
        this.rseCtlrIp = req.getRseCtlrIp();
        this.rseCtlrPort = req.getRseCtlrPort();
        this.rseCtlrLocalNo = req.getRseCtlrLocalNo();
        this.rseTypeCd = req.getRseTypeCd();
        this.istlLctnNm = req.getIstlLctnNm();
        this.istlLctnAddr = req.getIstlLctnAddr();
        this.xCrdn = req.getXCrdn();
        this.yCrdn = req.getYCrdn();
        this.rseMcuId = req.getRseMcuId();
        this.logCnncId = req.getLogCnncId();
        this.logCnncPw = req.getLogCnncPw();
        this.mnfcCmpyCd = req.getMnfcCmpyCd();
        this.clctAbnrBasi = req.getClctAbnrBasi();
        this.delYn = req.getDelYn();
    }

}
