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

import com.its.op.dto.its.rse.TbRseSectDto;
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_SECT")
public class TbRseSect implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("RSE 구간 아이디")  // N NUMBER(10)
    @Id
    @Column(name = "RSE_SECT_ID", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long rseSectId;

    @ApiModelProperty("구간 길이")  // Y NUMBER(5)
    @Column(name = "SECT_LNGT", columnDefinition = "NUMBER", length = 5)
    private Integer sectLngt;

    @ApiModelProperty("RSE 구간 명")  // Y VARCHAR2(60)
    @Column(name = "RSE_SECT_NM", length = 60)
    private String rseSectNm;

    @ApiModelProperty("시작 지점 명")  // Y VARCHAR2(60)
    @Column(name = "STRT_SPOT_NM", length = 60)
    private String strtSpotNm;

    @ApiModelProperty("종료 지점 명")  // Y VARCHAR2(60)
    @Column(name = "END_SPOT_NM", length = 60)
    private String endSpotNm;

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

    @ApiModelProperty("시작 RSE 제어기 번호")  // N NUMBER(10)
    @Column(name = "STRT_RSE_CTLR_NMBR", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long strtRseCtlrNmbr;

    @ApiModelProperty("종료 RSE 제어기 번호")  // N NUMBER(10)
    @Column(name = "END_RSE_CTLR_NMBR", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long endRseCtlrNmbr;

    public TbRseSectDto toDto() {
        return TbRseSectDto.builder()
                .rseSectId(this.rseSectId)
                .sectLngt(this.sectLngt)
                .rseSectNm(this.rseSectNm)
                .strtSpotNm(this.strtSpotNm)
                .endSpotNm(this.endSpotNm)
                .delYn(this.delYn)
                .strtRseCtlrNmbr(this.strtRseCtlrNmbr)
                .endRseCtlrNmbr(this.endRseCtlrNmbr)
                .build();
    }

    public TbRseSect(Long rseSectId) {
        this.rseSectId = rseSectId;
    }

    public void updateInfo(TbRseSectDto.TbRseSectUpdReq req) {
        this.sectLngt = req.getSectLngt();
        this.rseSectNm = req.getRseSectNm();
        this.strtSpotNm = req.getStrtSpotNm();
        this.endSpotNm = req.getEndSpotNm();
        this.delYn = req.getDelYn();
        this.strtRseCtlrNmbr = req.getStrtRseCtlrNmbr();
        this.endRseCtlrNmbr = req.getEndRseCtlrNmbr();
    }

}
