package com.its.op.entity.its.scrs;

import com.its.op.dto.its.scrs.TbScIxrGemtMngmDto;
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;

/**
 * 교차로 기하구조 관리 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("교차로 기하구조 관리")
@Entity
@Table(name = "TB_SC_IXR_GEMT_MNGM")
@IdClass(TbScIxrGemtMngmKey.class)
public class TbScIxrGemtMngm implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("교차로 ID")  // N VARCHAR2(10)
    @Id
    @Column(name = "IXR_ID", nullable = false, length = 10)
    private String ixrId;

    @ApiModelProperty("방향 구분(01:북, 02:동, 03:남, 04:서, 05:북동, 06:남동, 07:남서, 08:북서)")  // N NUMBER(1)
    @Id
    @Column(name = "DRCT_DVSN_CD", nullable = false, columnDefinition = "NUMBER", length = 1)
    private Integer drctDvsnCd;

    @ApiModelProperty("접근로 전체 차로 수")  // Y NUMBER(1)
    @Column(name = "ACRD_WHOL_LANE_CNT", columnDefinition = "NUMBER", length = 1)
    private Integer acrdWholLaneCnt;

    @ApiModelProperty("좌회전 형태")  // Y NUMBER(1)
    @Column(name = "LEFT_SHPE", columnDefinition = "NUMBER", length = 1)
    private Integer leftShpe;

    @ApiModelProperty("우회전 형태")  // Y NUMBER(1)
    @Column(name = "RGHT_SHPE", columnDefinition = "NUMBER", length = 1)
    private Integer rghtShpe;

    @ApiModelProperty("좌회전 전용 차로 수")  // Y NUMBER(1)
    @Column(name = "LEFT_DVRS_LANE_CNT", columnDefinition = "NUMBER", length = 1)
    private Integer leftDvrsLaneCnt;

    @ApiModelProperty("직진 전용 차로 수")  // Y NUMBER(1)
    @Column(name = "GO_DVRS_LANE_CNT", columnDefinition = "NUMBER", length = 1)
    private Integer goDvrsLaneCnt;

    @ApiModelProperty("우회전 전용 차로 수")  // Y NUMBER(1)
    @Column(name = "RGHT_DVRS_LANE_CNT", columnDefinition = "NUMBER", length = 1)
    private Integer rghtDvrsLaneCnt;

    @ApiModelProperty("좌회전 차로 수")  // Y NUMBER(1)
    @Column(name = "LEFT_LANE_CNT", columnDefinition = "NUMBER", length = 1)
    private Integer leftLaneCnt;

    @ApiModelProperty("우회전 차로 수")  // Y NUMBER(1)
    @Column(name = "RGHT_LANE_CNT", columnDefinition = "NUMBER", length = 1)
    private Integer rghtLaneCnt;

    @ApiModelProperty("방향 X 좌표")  // Y VARCHAR2(20)
    @Column(name = "DRCT_X_CRDN", length = 20)
    private String drctXCrdn;

    @ApiModelProperty("방향 Y 좌표")  // Y VARCHAR2(20)
    @Column(name = "DRCT_Y_CRDN", length = 20)
    private String drctYCrdn;

    @ApiModelProperty("비보호 좌회전")  // Y NUMBER(1)
    @Column(name = "UPRT_LEFT", columnDefinition = "NUMBER", length = 1)
    private Integer uprtLeft;

    @ApiModelProperty("옵셋")  // Y NUMBER(3)
    @Column(name = "OFST", columnDefinition = "NUMBER", length = 3)
    private Integer ofst;

    @ApiModelProperty("비보호 좌회전 차량 대수")  // Y NUMBER(4)
    @Column(name = "UPRT_LEFT_VHCL_UNUM", columnDefinition = "NUMBER", length = 4)
    private Integer uprtLeftVhclUnum;

    @ApiModelProperty("신호 운영 형태(0:양방향보호좌회전, 1:직좌동시신호, 2:비보호좌회전)")  // Y NUMBER(1)
    @Column(name = "SGNL_OPER_SHPE", columnDefinition = "NUMBER", length = 1)
    private Integer sgnlOperShpe;

    @ApiModelProperty("버스 전용 차로 수")  // Y NUMBER(1)
    @Column(name = "BUS_DVRS_LANE_CNT", columnDefinition = "NUMBER", length = 1)
    private Integer busDvrsLaneCnt;

    @ApiModelProperty("버스 전용 차로 유형")  // Y NUMBER(1)
    @Column(name = "BUS_DVRS_LANE_TYPE", columnDefinition = "NUMBER", length = 1)
    private Integer busDvrsLaneType;

    public TbScIxrGemtMngmDto toDto() {
        return TbScIxrGemtMngmDto.builder()
                .ixrId(this.ixrId)
                .drctDvsnCd(this.drctDvsnCd)
                .acrdWholLaneCnt(this.acrdWholLaneCnt)
                .leftShpe(this.leftShpe)
                .rghtShpe(this.rghtShpe)
                .leftDvrsLaneCnt(this.leftDvrsLaneCnt)
                .goDvrsLaneCnt(this.goDvrsLaneCnt)
                .rghtDvrsLaneCnt(this.rghtDvrsLaneCnt)
                .leftLaneCnt(this.leftLaneCnt)
                .rghtLaneCnt(this.rghtLaneCnt)
                .drctXCrdn(this.drctXCrdn)
                .drctYCrdn(this.drctYCrdn)
                .uprtLeft(this.uprtLeft)
                .ofst(this.ofst)
                .uprtLeftVhclUnum(this.uprtLeftVhclUnum)
                .sgnlOperShpe(this.sgnlOperShpe)
                .busDvrsLaneCnt(this.busDvrsLaneCnt)
                .busDvrsLaneType(this.busDvrsLaneType)
                .build();
    }

    public TbScIxrGemtMngm(String ixrId, Integer drctDvsnCd) {
        this.ixrId = ixrId;
        this.drctDvsnCd = drctDvsnCd;
    }

    public void updateInfo(TbScIxrGemtMngmDto.TbScIxrGemtMngmUpdReq req) {
        this.acrdWholLaneCnt = req.getAcrdWholLaneCnt();
        this.leftShpe = req.getLeftShpe();
        this.rghtShpe = req.getRghtShpe();
        this.leftDvrsLaneCnt = req.getLeftDvrsLaneCnt();
        this.goDvrsLaneCnt = req.getGoDvrsLaneCnt();
        this.rghtDvrsLaneCnt = req.getRghtDvrsLaneCnt();
        this.leftLaneCnt = req.getLeftLaneCnt();
        this.rghtLaneCnt = req.getRghtLaneCnt();
        this.drctXCrdn = req.getDrctXCrdn();
        this.drctYCrdn = req.getDrctYCrdn();
        this.uprtLeft = req.getUprtLeft();
        this.ofst = req.getOfst();
        this.uprtLeftVhclUnum = req.getUprtLeftVhclUnum();
        this.sgnlOperShpe = req.getSgnlOperShpe();
        this.busDvrsLaneCnt = req.getBusDvrsLaneCnt();
        this.busDvrsLaneType = req.getBusDvrsLaneType();
    }

}
