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

import com.its.op.dto.its.rse.TbRseOffrDrctDto;
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_OFFR_DRCT")
@IdClass(TbRseOffrDrctKey.class)
public class TbRseOffrDrct 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("OBU 진입 방향 번호")  // N NUMBER(1)
    @Id
    @Column(name = "OBU_ENTR_DRCT_NMBR", nullable = false, columnDefinition = "NUMBER", length = 1)
    private Integer obuEntrDrctNmbr;

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

    @ApiModelProperty("교차로 방향 개수")  // N NUMBER(1)
    @Column(name = "IXR_DRCT_NUM", nullable = false, columnDefinition = "NUMBER", length = 1)
    private Integer ixrDrctNum;

    public TbRseOffrDrctDto toDto() {
        return TbRseOffrDrctDto.builder()
                .rseCtlrNmbr(this.rseCtlrNmbr)
                .obuEntrDrctNmbr(this.obuEntrDrctNmbr)
                .preRseCtlrNmbr(this.preRseCtlrNmbr)
                .ixrDrctNum(this.ixrDrctNum)
                .build();
    }

    public TbRseOffrDrct(Long rseCtlrNmbr, Integer obuEntrDrctNmbr) {
        this.rseCtlrNmbr = rseCtlrNmbr;
        this.obuEntrDrctNmbr = obuEntrDrctNmbr;
    }

    public void updateInfo(TbRseOffrDrctDto.TbRseOffrDrctUpdReq req) {
        this.preRseCtlrNmbr = req.getPreRseCtlrNmbr();
        this.ixrDrctNum = req.getIxrDrctNum();
    }

}
