package com.its.op.entity.its.link;

import com.its.op.dto.its.link.TbLinkStat15mDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

/**
 * 링크 15분 통계 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("링크 15분 통계")
@Entity
@Table(name = "TB_LINK_STAT_15M")
@IdClass(TbLinkStat15mKey.class)
public class TbLinkStat15m implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("링크ID")  // N NUMBER(10)
    @Id
    @Column(name = "LINK_ID", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long linkId;

    @ApiModelProperty("통계 일시")  // N VARCHAR(14)
    @Id
    @Column(name = "STAT_DT", nullable = false, length = 14)
    private String statDt;

    @ApiModelProperty("요일 유형 코드")  // Y VARCHAR(7)
    @Column(name = "DAY_TYPE_CD", length = 7)
    private String dayTypeCd;

    @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(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 NUMBER(3)
    @Column(name = "DATA_NUM", columnDefinition = "NUMBER", length = 3)
    private Integer dataNum;

    public TbLinkStat15mDto toDto() {
        return TbLinkStat15mDto.builder()
                .linkId(this.linkId)
                .statDt(this.statDt)
                .dayTypeCd(this.dayTypeCd)
                .tfvl(this.tfvl)
                .sped(this.sped)
                .ocpyRate(this.ocpyRate)
                .trvlHh(this.trvlHh)
                .dataNum(this.dataNum)
                .build();
    }

    public TbLinkStat15m(Long linkId, String statDt) {
        this.linkId = linkId;
        this.statDt = statDt;
    }

    public void updateInfo(TbLinkStat15mDto.TbLink15mStatUpdReq req) {
        this.dayTypeCd = req.getDayTypeCd();
        this.tfvl = req.getTfvl();
        this.sped = req.getSped();
        this.ocpyRate = req.getOcpyRate();
        this.trvlHh = req.getTrvlHh();
        this.dataNum = req.getDataNum();
    }

}
