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

import com.its.api.its.global.CodeManager;
import com.its.api.its.model.dto.ifsc.TbIfscTrafHsDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.*;
import java.io.Serializable;

/**
 * 정보제공구간 소통상황 이력 Entity Class
 */
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("정보제공구간 소통상황 이력")
@Entity
@Table(name = "TB_IFSC_TRAF_HS")
@IdClass(TbIfscTrafHsKey.class)
public class TbIfscTrafHs implements Serializable {
    private static final long serialVersionUID = 1L;

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

    @ApiModelProperty("가공 일시")  // N VARCHAR(14)
    @Id
    @Column(name = "PRCN_DT", nullable = false, length = 14)
    private String prcnDt;

    @ApiModelProperty("교통량")  // Y NUMBER(6)
    @Column(name = "TFVL", columnDefinition = "NUMBER", length = 6)
    private Integer tfvl;

    @ApiModelProperty("속도")  // Y NUMBER(3)
    @Column(name = "SPED", columnDefinition = "NUMBER", length = 3)
    private Integer sped;

    @ApiModelProperty("패턴 속도")  // Y NUMBER(3)
    @Column(name = "PTRN_SPED", columnDefinition = "NUMBER", length = 3)
    private Integer ptrnSped;

    @ApiModelProperty("점유 율")  // Y NUMBER(5,2)
    @Column(name = "OCPY_RATE", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double ocpyRate;

    @ApiModelProperty("통행 시간")  // Y NUMBER(6)
    @Column(name = "TRVL_HH", columnDefinition = "NUMBER", length = 6)
    private Integer trvlHh;

    @ApiModelProperty("소통 등급 코드")  // Y VARCHAR(7)
    @Column(name = "CMTR_GRAD_CD", length = 7)
    private String cmtrGradCd;

    @ApiModelProperty("데이터 개수")  // Y NUMBER(3)
    @Column(name = "DATA_NUM", columnDefinition = "NUMBER", length = 3)
    private Integer dataNum;

    public TbIfscTrafHsDto toDto() {
        TbIfscTrafHsDto dto = TbIfscTrafHsDto.builder()
                .ifscId(this.ifscId)
                .prcnDt(this.prcnDt)
                .tfvl(this.tfvl)
                .sped(this.sped)
                .ptrnSped(this.ptrnSped)
                .ocpyRate(this.ocpyRate)
                .trvlHh(this.trvlHh)
                .cmtrGradCd(this.cmtrGradCd)
                .dataNum(this.dataNum)
                .build();

        dto.setCmtrGradDesc(CodeManager.getCodeDescShort(CodeManager.CMTR_GRAD_CD, this.cmtrGradCd));

        return dto;
    }

}
