package com.its.api.its.model.entity.vms;

import com.its.api.its.model.dto.vms.TbVmsIfscDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.ArrayList;

/**
 * VMS 정보제공구간 Entity Class
 */
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("VMS 정보제공구간")
@Entity
@Table(name = "TB_VMS_IFSC")
public class TbVmsIfsc implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("VMS 정보제공구간 ID")  // N NUMBER(10)
    @Id
    @Column(name = "VMS_IFSC_ID", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long vmsIfscId;

    @ApiModelProperty("VMS 정보제공구간 명")  // Y VARCHAR(60)
    @Column(name = "VMS_IFSC_NM", length = 60)
    private String vmsIfscNm;

    @ApiModelProperty("편집 코드")  // Y VARCHAR(7)
    @Column(name = "EDTN_CD", length = 7)
    private String edtnCd;

    @ApiModelProperty("표출 시작 노드 명")  // Y VARCHAR(30)
    @Column(name = "DSPL_STRT_NODE_NM", length = 30)
    private String dsplStrtNodeNm;

    @ApiModelProperty("표출 종료 노드 명")  // Y VARCHAR(30)
    @Column(name = "DSPL_END_NODE_NM", length = 30)
    private String dsplEndNodeNm;

    @ApiModelProperty("우회도로 ID")  // Y NUMBER(10)
    @Column(name = "DETR_ID", columnDefinition = "NUMBER", length = 10)
    private Long detrId;

    @ApiModelProperty("도로명")  // Y VARCHAR(30)
    @Column(name = "ROAD_NM", length = 30)
    private String roadNm;

    @ApiModelProperty("지점명")  // Y VARCHAR(30)
    @Column(name = "SPOT_NM", length = 30)
    private String spotNm;

    @ApiModelProperty("축정보 생성용")  // Y CHAR(1)
    @Column(name = "AXIS_YN", columnDefinition = "CHAR", length = 1)
    private String axisYn;

    public TbVmsIfscDto toDto() {
        return TbVmsIfscDto.builder()
                .vmsIfscId(this.vmsIfscId)
                .vmsIfscNm(this.vmsIfscNm)
                .edtnCd(this.edtnCd)
                .dsplStrtNodeNm(this.dsplStrtNodeNm)
                .dsplEndNodeNm(this.dsplEndNodeNm)
                .detrId(this.detrId)
                .roadNm(this.roadNm)
                .spotNm(this.spotNm)
                .axisYn(this.axisYn)
                .ifscs(new ArrayList<>())
                .build();
    }

    public TbVmsIfsc(Long vmsIfscId) {
        this.vmsIfscId = vmsIfscId;
    }

    public void updateInfo(TbVmsIfscDto.TbVmsIfscUpdReq req) {
        this.vmsIfscNm = req.getVmsIfscNm();
        this.edtnCd = req.getEdtnCd();
        this.dsplStrtNodeNm = req.getDsplStrtNodeNm();
        this.dsplEndNodeNm = req.getDsplEndNodeNm();
        this.detrId = req.getDetrId();
        this.roadNm = req.getRoadNm();
        this.spotNm = req.getSpotNm();
        this.axisYn = req.getAxisYn();
    }

}
