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

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

/**
 * 교차로 관리 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("교차로 관리")
@Entity
@Table(name = "TB_SC_IXR_MNGM")
public class TbScIxrMngm 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("교차로 명")  // Y VARCHAR2(50)
    @Column(name = "IXR_NM", length = 50)
    private String ixrNm;

    @ApiModelProperty("현시 수")  // Y NUMBER(1)
    @Column(name = "PHAS_CNT", columnDefinition = "NUMBER", length = 1)
    private Integer phasCnt;

    @ApiModelProperty("지점 특성")  // Y VARCHAR2(20)
    @Column(name = "SPOT_FETR", length = 20)
    private String spotFetr;

    @ApiModelProperty("교차로 X 좌표")  // Y VARCHAR2(20)
    @Column(name = "IXR_X_CRDN", length = 20)
    private String ixrXCrdn;

    @ApiModelProperty("교차로 Y 좌표")  // Y VARCHAR2(20)
    @Column(name = "IXR_Y_CRDN", length = 20)
    private String ixrYCrdn;

    @ApiModelProperty("교차로 유형")  // Y NUMBER(1)
    @Column(name = "IXR_TYPE", columnDefinition = "NUMBER", length = 1)
    private Integer ixrType;

    @ApiModelProperty("구분")  // Y NUMBER(1)
    @Column(name = "DVSN", columnDefinition = "NUMBER", length = 1)
    private Integer dvsn;

    @ApiModelProperty("사용 유무")  // Y NUMBER(1)
    @Column(name = "USE_EN", columnDefinition = "NUMBER", length = 1)
    private Integer useEn;

    @ApiModelProperty("노드ID")  // N NUMBER(10)
    @Column(name = "NODE_ID", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long nodeId;

    public TbScIxrMngmDto toDto() {
        return TbScIxrMngmDto.builder()
                .ixrId(this.ixrId)
                .ixrNm(this.ixrNm)
                .phasCnt(this.phasCnt)
                .spotFetr(this.spotFetr)
                .ixrXCrdn(this.ixrXCrdn)
                .ixrYCrdn(this.ixrYCrdn)
                .ixrType(this.ixrType)
                .dvsn(this.dvsn)
                .useEn(this.useEn)
                .nodeId(this.nodeId)
                .build();
    }

    public TbScIxrMngm(String ixrId) {
        this.ixrId = ixrId;
    }

    public void updateInfo(TbScIxrMngmDto.TbScIxrMngmUpdReq req) {
        this.ixrNm = req.getIxrNm();
        this.phasCnt = req.getPhasCnt();
        this.spotFetr = req.getSpotFetr();
        this.ixrXCrdn = req.getIxrXCrdn();
        this.ixrYCrdn = req.getIxrYCrdn();
        this.ixrType = req.getIxrType();
        this.dvsn = req.getDvsn();
        this.useEn = req.getUseEn();
        this.nodeId = req.getNodeId();
    }

}
