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

import com.its.op.dto.its.rse.TbRseCtlrSttsHsDto;
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.*;
import java.io.Serializable;

/**
 * RSE 상태 이력 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("RSE 상태 이력")
@Entity
@Table(name = "TB_RSE_CTLR_STTS_HS")
@IdClass(TbRseCtlrSttsHsKey.class)
public class TbRseCtlrSttsHs implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("생성 일시")  // N VARCHAR2(14)
    @Id
    @Column(name = "CRTN_DT", nullable = false, length = 14)
    private String crtnDt;

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

    @ApiModelProperty("통신 상태")  // Y VARCHAR2(7)
    @Column(name = "CMNC_STTS_CD", length = 7)
    private String cmncSttsCd;

    @ApiModelProperty("제어 장치 상태")  // Y VARCHAR2(7)
    @Column(name = "CNTL_DEVC_STTS", length = 7)
    private String cntlDevcStts;

    @ApiModelProperty("안테나 1 상태")  // Y VARCHAR2(7)
    @Column(name = "ATN_1_STTS", length = 7)
    private String atn1Stts;

    @ApiModelProperty("안테나 2 상태")  // Y VARCHAR2(7)
    @Column(name = "ATN_2_STTS", length = 7)
    private String atn2Stts;

    @ApiModelProperty("안테나 3 상태")  // Y VARCHAR2(7)
    @Column(name = "ATN_3_STTS", length = 7)
    private String atn3Stts;

    @ApiModelProperty("안테나 4 상태")  // Y VARCHAR2(7)
    @Column(name = "ATN_4_STTS", length = 7)
    private String atn4Stts;

    @ApiModelProperty("안테나 1 동작")  // Y VARCHAR2(7)
    @Column(name = "ATN_1_MTNS", length = 7)
    private String atn1Mtns;

    @ApiModelProperty("안테나 2 동작")  // Y VARCHAR2(7)
    @Column(name = "ATN_2_MTNS", length = 7)
    private String atn2Mtns;

    @ApiModelProperty("안테나 3 동작")  // Y VARCHAR2(7)
    @Column(name = "ATN_3_MTNS", length = 7)
    private String atn3Mtns;

    @ApiModelProperty("안테나 4 동작")  // Y VARCHAR2(7)
    @Column(name = "ATN_4_MTNS", length = 7)
    private String atn4Mtns;

    public TbRseCtlrSttsHsDto toDto() {
        return TbRseCtlrSttsHsDto.builder()
                .crtnDt(this.crtnDt)
                .rseCtlrNmbr(this.rseCtlrNmbr)
                .cmncSttsCd(this.cmncSttsCd)
                .cntlDevcStts(this.cntlDevcStts)
                .atn1Stts(this.atn1Stts)
                .atn2Stts(this.atn2Stts)
                .atn3Stts(this.atn3Stts)
                .atn4Stts(this.atn4Stts)
                .atn1Mtns(this.atn1Mtns)
                .atn2Mtns(this.atn2Mtns)
                .atn3Mtns(this.atn3Mtns)
                .atn4Mtns(this.atn4Mtns)
                .build();
    }

    public TbRseCtlrSttsHs(String crtnDt, Long rseCtlrNmbr) {
        this.crtnDt = crtnDt;
        this.rseCtlrNmbr = rseCtlrNmbr;
    }

    public void updateInfo(TbRseCtlrSttsHsDto.TbRseCtlrSttsHsUpdReq req) {
        this.cmncSttsCd = req.getCmncSttsCd();
        this.cntlDevcStts = req.getCntlDevcStts();
        this.atn1Stts = req.getAtn1Stts();
        this.atn2Stts = req.getAtn2Stts();
        this.atn3Stts = req.getAtn3Stts();
        this.atn4Stts = req.getAtn4Stts();
        this.atn1Mtns = req.getAtn1Mtns();
        this.atn2Mtns = req.getAtn2Mtns();
        this.atn3Mtns = req.getAtn3Mtns();
        this.atn4Mtns = req.getAtn4Mtns();
    }

}
