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

import com.its.op.dto.its.scrs.TbScTrfcCndtMngmDto;
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_TRFC_CNDT_MNGM")
@IdClass(TbScTrfcCndtMngmKey.class)
public class TbScTrfcCndtMngm 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 VARCHAR2(1)
    @Column(name = "BUS_BAY_EN", length = 1)
    private String busBayEn;

    @ApiModelProperty("노상 주차 유무")  // Y VARCHAR2(1)
    @Column(name = "STRE_PARK_EN", length = 1)
    private String streParkEn;

    @ApiModelProperty("상류 링크 길이")  // Y NUMBER(3)
    @Column(name = "UPST_LINK_LNGT", columnDefinition = "NUMBER", length = 3)
    private Integer upstLinkLngt;

    @ApiModelProperty("경사")  // Y NUMBER(3)
    @Column(name = "HPEV", columnDefinition = "NUMBER", length = 3)
    private Integer hpev;

    @ApiModelProperty("좌회전 곡선 반경")  // Y NUMBER(3)
    @Column(name = "LEFT_CURV_RADS", columnDefinition = "NUMBER", length = 3)
    private Integer leftCurvRads;

    @ApiModelProperty("평균 차로폭")  // Y NUMBER(3,1)
    @Column(name = "AVRG_LAWH", columnDefinition = "NUMBER", length = 3, precision = 1)
    private Double avrgLawh;

    @ApiModelProperty("버스 정류장 거리")  // Y NUMBER(3)
    @Column(name = "BUS_STTN_DSTC", columnDefinition = "NUMBER", length = 3)
    private Integer busSttnDstc;

    @ApiModelProperty("첨두 시간 계수")  // Y NUMBER(2)
    @Column(name = "PEAK_HH_FCTR", columnDefinition = "NUMBER", length = 2)
    private Integer peakHhFctr;

    @ApiModelProperty("U 턴 교통량")  // Y NUMBER(4)
    @Column(name = "U_TURN_TFVL", columnDefinition = "NUMBER", length = 4)
    private Integer uTurnTfvl;

    @ApiModelProperty("진입 교통량")  // Y NUMBER(4)
    @Column(name = "ENTR_TFVL", columnDefinition = "NUMBER", length = 4)
    private Integer entrTfvl;

    @ApiModelProperty("진출 교통량")  // Y NUMBER(4)
    @Column(name = "EXIT_TFVL", columnDefinition = "NUMBER", length = 4)
    private Integer exitTfvl;

    @ApiModelProperty("주차 활동 대수")  // Y NUMBER(4)
    @Column(name = "PARK_ACTN_UNUM", columnDefinition = "NUMBER", length = 4)
    private Integer parkActnUnum;

    @ApiModelProperty("횡단 보행 수")  // Y NUMBER(4)
    @Column(name = "CROS_WALK_CNT", columnDefinition = "NUMBER", length = 4)
    private Integer crosWalkCnt;

    @ApiModelProperty("순행 속도")  // Y NUMBER(3)
    @Column(name = "CRUS_SPED", columnDefinition = "NUMBER", length = 3)
    private Integer crusSped;

    @ApiModelProperty("초기 대기 차량 대수")  // Y NUMBER(4)
    @Column(name = "INTL_ATMP_VHCL_UNUM", columnDefinition = "NUMBER", length = 4)
    private Integer intlAtmpVhclUnum;

    @ApiModelProperty("보행 신호 시간")  // Y NUMBER(3)
    @Column(name = "WALK_SGNL_HH", columnDefinition = "NUMBER", length = 3)
    private Integer walkSgnlHh;

    @ApiModelProperty("버스 정차 대수")  // Y NUMBER(4)
    @Column(name = "BUS_STOP_UNUM", columnDefinition = "NUMBER", length = 4)
    private Integer busStopUnum;

    @ApiModelProperty("상류 정류장 이격 거리")  // Y NUMBER(3)
    @Column(name = "UPST_STTN_DSTC", columnDefinition = "NUMBER", length = 3)
    private Integer upstSttnDstc;

    public TbScTrfcCndtMngmDto toDto() {
        return TbScTrfcCndtMngmDto.builder()
                .ixrId(this.ixrId)
                .drctDvsnCd(this.drctDvsnCd)
                .busBayEn(this.busBayEn)
                .streParkEn(this.streParkEn)
                .upstLinkLngt(this.upstLinkLngt)
                .hpev(this.hpev)
                .leftCurvRads(this.leftCurvRads)
                .avrgLawh(this.avrgLawh)
                .busSttnDstc(this.busSttnDstc)
                .peakHhFctr(this.peakHhFctr)
                .uTurnTfvl(this.uTurnTfvl)
                .entrTfvl(this.entrTfvl)
                .exitTfvl(this.exitTfvl)
                .parkActnUnum(this.parkActnUnum)
                .crosWalkCnt(this.crosWalkCnt)
                .crusSped(this.crusSped)
                .intlAtmpVhclUnum(this.intlAtmpVhclUnum)
                .walkSgnlHh(this.walkSgnlHh)
                .busStopUnum(this.busStopUnum)
                .upstSttnDstc(this.upstSttnDstc)
                .build();
    }

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

    public void updateInfo(TbScTrfcCndtMngmDto.TbScTrfcCndtMngmUpdReq req) {
        this.busBayEn = req.getBusBayEn();
        this.streParkEn = req.getStreParkEn();
        this.upstLinkLngt = req.getUpstLinkLngt();
        this.hpev = req.getHpev();
        this.leftCurvRads = req.getLeftCurvRads();
        this.avrgLawh = req.getAvrgLawh();
        this.busSttnDstc = req.getBusSttnDstc();
        this.peakHhFctr = req.getPeakHhFctr();
        this.uTurnTfvl = req.getUTurnTfvl();
        this.entrTfvl = req.getEntrTfvl();
        this.exitTfvl = req.getExitTfvl();
        this.parkActnUnum = req.getParkActnUnum();
        this.crosWalkCnt = req.getCrosWalkCnt();
        this.crusSped = req.getCrusSped();
        this.intlAtmpVhclUnum = req.getIntlAtmpVhclUnum();
        this.walkSgnlHh = req.getWalkSgnlHh();
        this.busStopUnum = req.getBusStopUnum();
        this.upstSttnDstc = req.getUpstSttnDstc();
    }

}
