package com.its.op.entity.its.weather;

import com.its.op.global.CodeManager;
import com.its.op.dto.its.weather.TbVilgFrcsPnstDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

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

/**
 * 동네 예보 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("동네 예보")
@Entity
@Table(name = "TB_VILG_FRCS_PNST")
@IdClass(TbVilgFrcsPnstKey.class)
public class TbVilgFrcsPnst implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("동네 예보 구역 코드")  // N NUMBER(14)
    @Id
    @Column(name = "VILG_FRCS_ZONE_CD", nullable = false, columnDefinition = "NUMBER", length = 14)
    private Long vilgFrcsZoneCd;

    @ApiModelProperty("발표 일시")  // N VARCHAR(14)
    @Id
    @Column(name = "ANNC_DT", nullable = false, length = 14)
    private String anncDt;

    @ApiModelProperty("순서")  // N NUMBER(3)
    @Id
    @Column(name = "ORD", nullable = false, columnDefinition = "NUMBER", length = 3)
    private Integer ord;

    @ApiModelProperty("시간")  // Y NUMBER(3)
    @Column(name = "HH", columnDefinition = "NUMBER", length = 3)
    private Integer hh;

    @ApiModelProperty("일")  // Y NUMBER(3)
    @Column(name = "DD", columnDefinition = "NUMBER", length = 3)
    private Integer dd;

    @ApiModelProperty("현재 온도")  // Y NUMBER(6,3)
    @Column(name = "PRST_TMPR", columnDefinition = "NUMBER", length = 6, precision = 3)
    private Double prstTmpr;

    @ApiModelProperty("최고 온도")  // Y NUMBER(6,3)
    @Column(name = "HGHS_TMPR", columnDefinition = "NUMBER", length = 6, precision = 3)
    private Double hghsTmpr;

    @ApiModelProperty("최저 온도")  // Y NUMBER(6,3)
    @Column(name = "LWST_TMPR", columnDefinition = "NUMBER", length = 6, precision = 3)
    private Double lwstTmpr;

    @ApiModelProperty("대기 상태")  // Y NUMBER(2)
    @Column(name = "ATMP_STTS", columnDefinition = "NUMBER", length = 2)
    private Integer atmpStts;

    @ApiModelProperty("날씨 한글 명")  // Y VARCHAR(20)
    @Column(name = "WTCD_KOR_NM", length = 20)
    private String wtcdKorNm;

    @ApiModelProperty("강수 상태")  // Y NUMBER(3)
    @Column(name = "PRCP_STTS", columnDefinition = "NUMBER", length = 3)
    private Integer prcpStts;

    @ApiModelProperty("날씨 영문 명")  // Y VARCHAR(20)
    @Column(name = "WTCD_ENGL_NM", length = 20)
    private String wtcdEnglNm;

    @ApiModelProperty("강수 확률")  // Y NUMBER(5,2)
    @Column(name = "PRCP_PR", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double prcpPr;

    @ApiModelProperty("예상 강수량 12시간")  // Y NUMBER(5,2)
    @Column(name = "ESTM_PRAM_12HH", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double estmPram12hh;

    @ApiModelProperty("예상 눈 량 12시간")  // Y NUMBER(5,2)
    @Column(name = "ESTM_SNOW_AMUT_12HH", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double estmSnowAmut12hh;

    @ApiModelProperty("풍속")  // Y NUMBER(5,2)
    @Column(name = "WNSP", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double wnsp;

    @ApiModelProperty("풍향")  // Y NUMBER(2)
    @Column(name = "WNDR", columnDefinition = "NUMBER", length = 2)
    private Integer wndr;

    @ApiModelProperty("풍향 한글 명")  // Y VARCHAR(20)
    @Column(name = "WNDR_KOR_NM", length = 20)
    private String wndrKorNm;

    @ApiModelProperty("풍향 영문 명")  // Y VARCHAR(20)
    @Column(name = "WNDR_ENGL_NM", length = 20)
    private String wndrEnglNm;

    @ApiModelProperty("습도")  // Y NUMBER(5,2)
    @Column(name = "HMDT", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double hmdt;

    @ApiModelProperty("예상 강수 량 6시간")  // Y NUMBER(5,2)
    @Column(name = "ESTM_PRCP_AMUT_6HH", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double estmPrcpAmut6hh;

    @ApiModelProperty("예상 눈 량 6시간")  // Y NUMBER(5,2)
    @Column(name = "ESTM_SNOW_AMUT_6HH", columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double estmSnowAmut6hh;

    @OneToOne
    @JoinColumn(insertable=false, updatable=false, name="VILG_FRCS_ZONE_CD", referencedColumnName = "VILG_FRCS_ZONE_CD")
    @NotFound(action = NotFoundAction.IGNORE)
    private TbVilgFrcsZone frcs;

    public TbVilgFrcsPnstDto toDto() {
        TbVilgFrcsPnstDto dto = TbVilgFrcsPnstDto.builder()
                .vilgFrcsZoneCd(this.vilgFrcsZoneCd)
                .anncDt(this.anncDt)
                .ord(this.ord)
                .hh(this.hh)
                .dd(this.dd)
                .prstTmpr(this.prstTmpr)
                .hghsTmpr(this.hghsTmpr)
                .lwstTmpr(this.lwstTmpr)
                .atmpStts(this.atmpStts)
                .wtcdKorNm(this.wtcdKorNm)
                .prcpStts(this.prcpStts)
                .wtcdEnglNm(this.wtcdEnglNm)
                .prcpPr(this.prcpPr)
                .estmPram12hh(this.estmPram12hh)
                .estmSnowAmut12hh(this.estmSnowAmut12hh)
                .wnsp(this.wnsp)
                .wndr(this.wndr)
                .wndrKorNm(this.wndrKorNm)
                .wndrEnglNm(this.wndrEnglNm)
                .hmdt(this.hmdt)
                .estmPrcpAmut6hh(this.estmPrcpAmut6hh)
                .estmSnowAmut6hh(this.estmSnowAmut6hh)
                .build();

        if (this.frcs != null) {
            dto.setVilgFrcsZoneNm(this.frcs.getVilgFrcsZoneNm());
        }
        dto.setWtcdKorCd(CodeManager.getWeatherCode(this.wtcdKorNm));
        return dto;
    }

}
