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

import com.its.op.dto.its.weather.TbAtmpPltnPnstDto;
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_ATMP_PLTN_PNST")
public class TbAtmpPltnPnst implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("측정소 번호")  // N NUMBER(10)
    @Id
    @Column(name = "ATMP_STTN_NMBR", nullable = false, columnDefinition = "NUMBER", length = 10)
    private Long atmpSttnNmbr;

    @ApiModelProperty("측정 일시")  // Y VARCHAR(14)
    @Column(name = "MSRM_DT", length = 14)
    private String msrmDt;

    @ApiModelProperty("측정 시스템 명")  // Y VARCHAR(10)
    @Column(name = "MSRM_SYST_NM", length = 10)
    private String msrmSystNm;

    @ApiModelProperty("CO 값")  // Y VARCHAR(10)
    @Column(name = "CO_VAL", length = 10)
    private String coVal;

    @ApiModelProperty("SO2 값")  // Y VARCHAR(10)
    @Column(name = "SO2_VAL", length = 10)
    private String so2Val;

    @ApiModelProperty("NO2 값")  // Y VARCHAR(10)
    @Column(name = "NO2_VAL", length = 10)
    private String no2Val;

    @ApiModelProperty("O3 값")  // Y VARCHAR(10)
    @Column(name = "O3_VAL", length = 10)
    private String o3Val;

    @ApiModelProperty("PM10 값")  // Y VARCHAR(10)
    @Column(name = "PM10_VAL", length = 10)
    private String pm10Val;

    @ApiModelProperty("PM10 24시간 값")  // Y VARCHAR(10)
    @Column(name = "PM10_24HH_VAL", length = 10)
    private String pm1024hhVal;

    @ApiModelProperty("PM25 값")  // Y VARCHAR(10)
    @Column(name = "PM25_VAL", length = 10)
    private String pm25Val;

    @ApiModelProperty("PM25 24시간 값")  // Y VARCHAR(10)
    @Column(name = "PM25_24HH_VAL", length = 10)
    private String pm2524hhVal;

    @ApiModelProperty("통합 대기 값")  // Y VARCHAR(10)
    @Column(name = "INTG_ATMP_VAL", length = 10)
    private String intgAtmpVal;

    @ApiModelProperty("통합 대기 등급")  // Y VARCHAR(10)
    @Column(name = "INTG_ATMP_GRAD", length = 10)
    private String intgAtmpGrad;

    @ApiModelProperty("SO2 등급")  // Y VARCHAR(10)
    @Column(name = "SO2_GRAD", length = 10)
    private String so2Grad;

    @ApiModelProperty("CO 등급")  // Y VARCHAR(10)
    @Column(name = "CO_GRAD", length = 10)
    private String coGrad;

    @ApiModelProperty("O3 드급")  // Y VARCHAR(10)
    @Column(name = "O3_GRAD", length = 10)
    private String o3Grad;

    @ApiModelProperty("NO2 등급")  // Y VARCHAR(10)
    @Column(name = "NO2_GRAD", length = 10)
    private String no2Grad;

    @ApiModelProperty("PM10 24시간 등급")  // Y VARCHAR(10)
    @Column(name = "PM10_24HH_GRAD", length = 10)
    private String pm1024hhGrad;

    @ApiModelProperty("PM25 24시간 등급")  // Y VARCHAR(10)
    @Column(name = "PM25_24HH_GRAD", length = 10)
    private String pm2524hhGrad;

    @ApiModelProperty("PM10 1시간 등급")  // Y VARCHAR(10)
    @Column(name = "PM10_1HH_GRAD", length = 10)
    private String pm101hhGrad;

    @ApiModelProperty("PM25 1시간 등급")  // Y VARCHAR(10)
    @Column(name = "PM25_1HH_GRAD", length = 10)
    private String pm251hhGrad;

    @ApiModelProperty("갱신 일시")  // Y VARCHAR(14)
    @Column(name = "UPDT_DT", length = 14)
    private String updtDt;

    @OneToOne
    @JoinColumn(insertable=false, updatable=false, name="ATMP_STTN_NMBR", referencedColumnName = "ATMP_STTN_NMBR")
    @NotFound(action = NotFoundAction.IGNORE)
    private TbAtmpPltnSttn atmp;

    public TbAtmpPltnPnstDto toDto() {
        TbAtmpPltnPnstDto dto = TbAtmpPltnPnstDto.builder()
                .atmpSttnNmbr(this.atmpSttnNmbr)
                .msrmDt(this.msrmDt)
                .msrmSystNm(this.msrmSystNm)
                .coVal(this.coVal)
                .so2Val(this.so2Val)
                .no2Val(this.no2Val)
                .o3Val(this.o3Val)
                .pm10Val(this.pm10Val)
                .pm1024hhVal(this.pm1024hhVal)
                .pm25Val(this.pm25Val)
                .pm2524hhVal(this.pm2524hhVal)
                .intgAtmpVal(this.intgAtmpVal)
                .intgAtmpGrad(this.intgAtmpGrad)
                .so2Grad(this.so2Grad)
                .coGrad(this.coGrad)
                .o3Grad(this.o3Grad)
                .no2Grad(this.no2Grad)
                .pm1024hhGrad(this.pm1024hhGrad)
                .pm2524hhGrad(this.pm2524hhGrad)
                .pm101hhGrad(this.pm101hhGrad)
                .pm251hhGrad(this.pm251hhGrad)
                .updtDt(this.updtDt)
                .build();
        if (this.atmp != null) {
            dto.setAtmpSttnNm(this.atmp.getAtmpSttnNm());
        }
        dto.setGradDesc();
        return dto;
    }

    public TbAtmpPltnPnst(Long atmpSttnNmbr) {
        this.atmpSttnNmbr = atmpSttnNmbr;
    }

}
