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

import com.its.api.its.model.dto.atrd.TbAtrdDto;
import com.its.api.its.model.dto.atrd.TbAtrdRoadRltnDto;
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.List;

/**
 * 간선도로 Entity Class
 */
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("간선도로")
@Entity
@Table(name = "TB_ATRD")
public class TbAtrd implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("간선도로 ID")  // N VARCHAR(10)
    @Id
    @Column(name = "ATRD_ID", nullable = false, length = 10)
    private String atrdId;

    @ApiModelProperty("간선도로 명")  // Y VARCHAR(30)
    @Column(name = "ATRD_NM", length = 30)
    private String atrdNm;

    @ApiModelProperty("방향 코드")  // Y VARCHAR(7)
    @Column(name = "DRCT_CD", length = 7)
    private String drctCd;

    @ApiModelProperty("지역 코드")  // Y VARCHAR(7)
    @Column(name = "AREA_CD", length = 7)
    private String areaCd;

    @ApiModelProperty("삭제 여부")  // Y CHAR(1)
    @Column(name = "DEL_YN", columnDefinition = "CHAR", length = 1)
    private String delYn;

    public TbAtrdDto toDto(List<TbAtrdRoadRltnDto> roads) {
        TbAtrdDto dto = TbAtrdDto.builder()
                .atrdId(this.atrdId)
                .atrdNm(this.atrdNm)
                .drctCd(this.drctCd)
                .areaCd(this.areaCd)
                .delYn(this.delYn)
                .roads(roads)
                .build();

        if (this.drctCd.equals("0"))
            dto.setDrctDesc("상행");
        else
            dto.setDrctDesc("하행");

        return dto;
    }

    public TbAtrd(String atrdId) {
        this.atrdId = atrdId;
    }

    public void updateInfo(TbAtrdDto.TbAtrdUpdReq req) {
        this.atrdNm = req.getAtrdNm();
        this.drctCd = req.getDrctCd();
        this.areaCd = req.getAreaCd();
        this.delYn = req.getDelYn();
    }

}
