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

import com.its.op.dto.its.link.TbLinkParaDetlDto;
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_LINK_PARA_DETL")
public class TbLinkParaDetl implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("파라미터 ID")  // N NUMBER(10)
    @Id
    @Column(name = "PARA_ID", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long paraId;

    @ApiModelProperty("필터링 최소 교통량")  // Y NUMBER(6)
    @Column(name = "FLTR_MIN_TFVL", columnDefinition = "NUMBER", length = 6)
    private Integer fltrMinTfvl;

    @ApiModelProperty("필터링 최대 교통량")  // Y NUMBER(6)
    @Column(name = "FLTR_MAX_TFVL", columnDefinition = "NUMBER", length = 6)
    private Integer fltrMaxTfvl;

    @ApiModelProperty("필터링 최저 속도")  // Y NUMBER(3)
    @Column(name = "FLTR_LWST_SPED", columnDefinition = "NUMBER", length = 3)
    private Integer fltrLwstSped;

    @ApiModelProperty("필터링 최고 속도")  // Y NUMBER(3)
    @Column(name = "FLTR_HGHS_SPED", columnDefinition = "NUMBER", length = 3)
    private Integer fltrHghsSped;

    @ApiModelProperty("보정 가중치 평균 이전 1주기")  // Y NUMBER(5,2)
    @Column(name = "ADJS_WGHT_AVRG_PRE_1CYCL", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double adjsWghtAvrgPre1cycl;

    @ApiModelProperty("보정 가중치 평균 이전 2주기")  // Y NUMBER(5,2)
    @Column(name = "ADJS_WGHT_AVRG_PRE_2CYCL", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double adjsWghtAvrgPre2cycl;

    @ApiModelProperty("보정 가중치 평균 이전 3주기")  // Y NUMBER(5,2)
    @Column(name = "ADJS_WGHT_AVRG_PRE_3CYCL", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double adjsWghtAvrgPre3cycl;

    @ApiModelProperty("보정 15분 패턴 적용 여부")  // Y CHAR(1)
    @Column(name = "ADJS_PTRN_15M_APLY_YN", columnDefinition = "CHAR", length = 1)
    private String adjsPtrn15mAplyYn;

    @ApiModelProperty("보정 단기 결측 판단 주기")  // Y NUMBER(2)
    @Column(name = "ADJS_SHTR_MISS_DECS_CYCL", columnDefinition = "NUMBER", length = 2)
    private Integer adjsShtrMissDecsCycl;

    @ApiModelProperty("평활화 최저 속도 계수")  // Y NUMBER(3,2)
    @Column(name = "SMTH_LWST_SPED_FCTR", columnDefinition = "NUMBER", length = 3, precision = 2)
    private Double smthLwstSpedFctr;

    @ApiModelProperty("평활화 최고 속도 계수")  // Y NUMBER(3,2)
    @Column(name = "SMTH_HGHS_SPED_FCTR", columnDefinition = "NUMBER", length = 3, precision = 2)
    private Double smthHghsSpedFctr;

    @ApiModelProperty("평활화 가중치 평균 현재")  // Y NUMBER(5,2)
    @Column(name = "SMTH_WGHT_AVRG_PRST", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double smthWghtAvrgPrst;

    @ApiModelProperty("평활화 가중치 평균 이전 1주기")  // Y NUMBER(5,2)
    @Column(name = "SMTH_WGHT_AVRG_PRE_1CYCL", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double smthWghtAvrgPre1cycl;

    @ApiModelProperty("평활화 가중치 평균 이전 2주기")  // Y NUMBER(5,2)
    @Column(name = "SMTH_WGHT_AVRG_PRE_2CYCL", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double smthWghtAvrgPre2cycl;

    @ApiModelProperty("패턴업데이트계수")  // Y NUMBER(5,2)
    @Column(name = "PTRN_R", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double ptrnR;

    public TbLinkParaDetlDto toDto() {
        TbLinkParaDetlDto dto = TbLinkParaDetlDto.builder()
                .paraId(this.paraId)
                .fltrMinTfvl(this.fltrMinTfvl)
                .fltrMaxTfvl(this.fltrMaxTfvl)
                .fltrLwstSped(this.fltrLwstSped)
                .fltrHghsSped(this.fltrHghsSped)
                .adjsWghtAvrgPre1cycl(this.adjsWghtAvrgPre1cycl)
                .adjsWghtAvrgPre2cycl(this.adjsWghtAvrgPre2cycl)
                .adjsWghtAvrgPre3cycl(this.adjsWghtAvrgPre3cycl)
                .adjsPtrn15mAplyYn(this.adjsPtrn15mAplyYn)
                .adjsShtrMissDecsCycl(this.adjsShtrMissDecsCycl)
                .smthLwstSpedFctr(this.smthLwstSpedFctr)
                .smthHghsSpedFctr(this.smthHghsSpedFctr)
                .smthWghtAvrgPrst(this.smthWghtAvrgPrst)
                .smthWghtAvrgPre1cycl(this.smthWghtAvrgPre1cycl)
                .smthWghtAvrgPre2cycl(this.smthWghtAvrgPre2cycl)
                .ptrnR(this.ptrnR)
                .build();

        if ("Y".equals(dto.getAdjsPtrn15mAplyYn())) dto.setAdjsPtrn15mAplyDesc("적용함");
        else dto.setAdjsPtrn15mAplyDesc("적용안함");

        return dto;
    }

    public TbLinkParaDetl(Long paraId) {
        this.paraId = paraId;
    }

    public void updateInfo(TbLinkParaDetlDto.TbLinkParaDetlUpdReq req) {
        this.fltrMinTfvl = req.getFltrMinTfvl();
        this.fltrMaxTfvl = req.getFltrMaxTfvl();
        this.fltrLwstSped = req.getFltrLwstSped();
        this.fltrHghsSped = req.getFltrHghsSped();
        this.adjsWghtAvrgPre1cycl = req.getAdjsWghtAvrgPre1cycl();
        this.adjsWghtAvrgPre2cycl = req.getAdjsWghtAvrgPre2cycl();
        this.adjsWghtAvrgPre3cycl = req.getAdjsWghtAvrgPre3cycl();
        this.adjsPtrn15mAplyYn = req.getAdjsPtrn15mAplyYn();
        this.adjsShtrMissDecsCycl = req.getAdjsShtrMissDecsCycl();
        this.smthLwstSpedFctr = req.getSmthLwstSpedFctr();
        this.smthHghsSpedFctr = req.getSmthHghsSpedFctr();
        this.smthWghtAvrgPrst = req.getSmthWghtAvrgPrst();
        this.smthWghtAvrgPre1cycl = req.getSmthWghtAvrgPre1cycl();
        this.smthWghtAvrgPre2cycl = req.getSmthWghtAvrgPre2cycl();
        this.ptrnR = req.getPtrnR();
    }

}
