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

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

    @ApiModelProperty("제공 구간 아이디")  // N NUMBER(10)
    @Id
    @Column(name = "OFFR_SECT_ID", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long offrSectId;

    @ApiModelProperty("제공 방향 명")  // Y VARCHAR2(30)
    @Column(name = "OFFR_DRCT_NM", length = 30)
    private String offrDrctNm;

    @ApiModelProperty("정체 기준 속도")  // Y NUMBER(3)
    @Column(name = "CNGS_BASI_SPED", columnDefinition = "NUMBER", length = 3)
    private Integer cngsBasiSped;

    @ApiModelProperty("지체 기준 속도")  // Y NUMBER(3)
    @Column(name = "DELY_BASI_SPED", columnDefinition = "NUMBER", length = 3)
    private Integer delyBasiSped;

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

    @ApiModelProperty("OBU 진입 방향 번호")  // N NUMBER(1)
    @Column(name = "OBU_ENTR_DRCT_NMBR", nullable = false, columnDefinition = "NUMBER", length = 1)
    private Integer obuEntrDrctNmbr;

    public TbRseOffrSectDto toDto() {
        return TbRseOffrSectDto.builder()
                .offrSectId(this.offrSectId)
                .offrDrctNm(this.offrDrctNm)
                .cngsBasiSped(this.cngsBasiSped)
                .delyBasiSped(this.delyBasiSped)
                .rseCtlrNmbr(this.rseCtlrNmbr)
                .obuEntrDrctNmbr(this.obuEntrDrctNmbr)
                .build();
    }

    public TbRseOffrSect(Long offrSectId) {
        this.offrSectId = offrSectId;
    }

    public void updateInfo(TbRseOffrSectDto.TbRseOffrSectUpdReq req) {
        this.offrDrctNm = req.getOffrDrctNm();
        this.cngsBasiSped = req.getCngsBasiSped();
        this.delyBasiSped = req.getDelyBasiSped();
        this.rseCtlrNmbr = req.getRseCtlrNmbr();
        this.obuEntrDrctNmbr = req.getObuEntrDrctNmbr();
    }

}
