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

import com.its.op.dto.its.rse.TbRseSectPassHsDto;
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_SECT_PASS_HS")
@IdClass(TbRseSectPassHsKey.class)
public class TbRseSectPassHs implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("RSE 구간 아이디")  // N VARCHAR2(8)
    @Id
    @Column(name = "RSE_SECT_ID", nullable = false, length = 8)
    private String rseSectId;

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

    @ApiModelProperty("OBU 인식 번호")  // N VARCHAR2(200)
    @Id
    @Column(name = "OBU_IDNT_NMBR", nullable = false, length = 200)
    private String obuIdntNmbr;

    @ApiModelProperty("시작 지점 통과 일시")  // N VARCHAR2(14)
    @Column(name = "STRT_SPOT_PASS_DT", nullable = false, length = 14)
    private String strtSpotPassDt;

    @ApiModelProperty("종료 지점 통과 일시")  // N VARCHAR2(14)
    @Column(name = "END_SPOT_PASS_DT", nullable = false, length = 14)
    private String endSpotPassDt;

    public TbRseSectPassHsDto toDto() {
        return TbRseSectPassHsDto.builder()
                .rseSectId(this.rseSectId)
                .crtnDt(this.crtnDt)
                .obuIdntNmbr(this.obuIdntNmbr)
                .strtSpotPassDt(this.strtSpotPassDt)
                .endSpotPassDt(this.endSpotPassDt)
                .build();
    }

    public TbRseSectPassHs(String rseSectId, String crtnDt, String obuIdntNmbr) {
        this.rseSectId = rseSectId;
        this.crtnDt = crtnDt;
        this.obuIdntNmbr = obuIdntNmbr;
    }

    public void updateInfo(TbRseSectPassHsDto.TbRseSectPassHsUpdReq req) {
        this.strtSpotPassDt = req.getStrtSpotPassDt();
        this.endSpotPassDt = req.getEndSpotPassDt();
    }

}
