package com.its.vms.dto;

import com.its.app.utils.ItsUtils;
import com.its.vms.domain.enums.eVmsColor;
import com.its.vms.entity.TbVmsAtmp;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

/**
 *  DTO Class
 */
@Data
@Builder
public class TbVmsAtmpDto implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long atmpSttnNmbr;
    private String atmpSttnNm;
    private String vmsDispNm;
    private String delYn;

    private String msrmDt;
    private String msrmSystNm;
    private String coVal;
    private String so2Val;
    private String no2Val;
    private String o3Val;
    private String pm10Val;
    private String pm1024hhVal;
    private String pm25Val;
    private String pm2524hhVal;
    private String intgAtmpVal;
    private String intgAtmpGrad;
    private String so2Grad;
    private String coGrad;
    private String o3Grad;
    private String no2Grad;
    private String pm1024hhGrad;
    private String pm2524hhGrad;
    private String pm101hhGrad;
    private String pm251hhGrad;
    private String updtDt;

    private boolean isSuccess;

    public TbVmsAtmp toEntity() {
        return TbVmsAtmp.builder()
                .atmpSttnNmbr(this.atmpSttnNmbr)
                .atmpSttnNm(this.atmpSttnNm)
                .vmsDispNm(this.vmsDispNm)
                .delYn(this.delYn)
                .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();
    }

    public void correct(TbVmsAtmpDto obj) {
        obj.setMsrmDt(this.msrmDt);
        obj.setMsrmSystNm(this.msrmSystNm);
        obj.setCoVal(this.coVal);
        obj.setSo2Val(this.so2Val);
        obj.setNo2Val(this.no2Val);
        obj.setO3Val(this.o3Val);
        obj.setPm10Val(this.pm10Val);
        obj.setPm1024hhVal(this.pm1024hhVal);
        obj.setPm25Val(this.pm25Val);
        obj.setPm2524hhVal(this.pm2524hhVal);
        obj.setIntgAtmpVal(this.intgAtmpVal);
        obj.setIntgAtmpGrad(this.intgAtmpGrad);
        obj.setSo2Grad(this.so2Grad);
        obj.setCoGrad(this.coGrad);
        obj.setO3Grad(this.o3Grad);
        obj.setNo2Grad(this.no2Grad);
        obj.setPm1024hhGrad(this.pm1024hhGrad);
        obj.setPm2524hhGrad(this.pm2524hhGrad);
        obj.setPm101hhGrad(this.pm101hhGrad);
        obj.setPm251hhGrad(this.pm251hhGrad);
        obj.setUpdtDt(this.updtDt);
        obj.setSuccess(this.isSuccess);
    }

    public String getPm10ValDesc(String unitGap, boolean AUnit) {
        // 미세먼지
        if (this.isSuccess) {
            if (AUnit)
                return this.pm10Val + unitGap + "㎍/㎥";
            else
                return this.pm10Val;
        }
        return (AUnit) ? "-" + unitGap + "㎍/㎥" : "-";
    }

    public String getPm25ValDesc(String unitGap, boolean AUnit) {
        //초미세먼지
        if (this.isSuccess) {
            if (AUnit)
                return this.pm25Val + unitGap + "㎍/㎥";
            else
                return this.pm25Val;
        }
        return (AUnit) ? "-" + unitGap + "㎍/㎥" : "-";
    }

    public String getAtmpValDesc() {
        //통합대기환경수치
        if (this.isSuccess) {
            return this.intgAtmpVal;
        }
        return "-";
    }

    public String getO3ValDesc(String unitGap, boolean AUnit) {
        //오존농도
        if (this.isSuccess) {
            if (AUnit)
                return this.o3Val + unitGap + "ppm";
            else
                return this.o3Val;
        }
        return (AUnit) ? "-" + unitGap + "ppm" : "-";
    }

    public String getGradeDesc(int AGrad) {
        if (!this.isSuccess) return "-";

        switch(AGrad) {
            case 1: return "좋음";
            case 2: return "보통";
            case 3: return "나쁨";
            case 4: return "매우나쁨";
        }
        return "-";
    }

    public int getGradeColor(int AGrad) {
        if (!this.isSuccess) return eVmsColor.color_red.getValue();//Color.GREEN.getRGB();

        switch(AGrad) {
            case 1: return eVmsColor.color_green.getValue();//밝은녹색(Lime)
            case 2: return eVmsColor.color_aqua.getValue();//하늘색(Aqua)
            case 3: return eVmsColor.color_orange.getValue();//주황색(Orange)
            case 4: return eVmsColor.color_red.getValue();//적색(Red)
        }
        return eVmsColor.color_red.getValue();
    }
    public String getPm10GradDesc() { return getGradeDesc(ItsUtils.parseIntDef(this.pm101hhGrad, 0)); }
    public String getPm25GradDesc() { return getGradeDesc(ItsUtils.parseIntDef(this.pm251hhGrad, 0)); }
    public String getAtmpGradDesc() { return getGradeDesc(ItsUtils.parseIntDef(this.intgAtmpGrad, 0)); }
    public String getO3GradDesc() { return getGradeDesc(ItsUtils.parseIntDef(this.o3Grad, 0)); }

    public int getPm10Color() { return getGradeColor(ItsUtils.parseIntDef(this.pm101hhGrad, 0)); }
    public int getPm25Color() { return getGradeColor(ItsUtils.parseIntDef(this.pm251hhGrad, 0)); }
    public int getAtmpColor() {
        return getGradeColor(ItsUtils.parseIntDef(this.intgAtmpGrad, 0));
    }
    public int getO3Color()   { return getGradeColor(ItsUtils.parseIntDef(this.o3Grad, 0)); }

}
