package com.inspect.infrared;

import com.inspect.infrared.domain.InfraredEntity;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Setter
@Getter
public class InfraredResponse {
    public static final String VALUE_ERROR = "1";
    public static final String VALUE_OK = "0";
    public static final String CODE_OK = "2000";
    public static final String CODE_IMG_ERROR = "2001";
    public static final String CODE_ANALYSIS_ERROR = "2002";
    public static final String TYPE = "infrared";
    public static final String WARN_HIGH = "高温告警";
    public static final String ALARM_HIGH = "高温预警";
    public static final String WARN_LOW = "低温告警";
    public static final String ALARM_LOW = "低温预警";
    private String requestId;
    private List<InfraredResponse.Param> resultList;

    public InfraredResponse() {
    }

    public InfraredResponse(String requestId) {
        this.requestId = requestId;
    }

    public boolean addParam(InfraredResponse.Param param) {
        if (this.resultList == null) {
            this.resultList = new ArrayList<>();
        }

        return this.resultList.add(param);
    }

    @Setter
    @Getter
    public static class Result {
        private String type = "infrared";
        private String code = "2000";
        private String resImageUrl;
        private String conf;
        private String value = "0";
        private String desc;
        private InfraredT infraredT;

        public Result() {
        }

        public Result(String resImageUrl) {
            this.resImageUrl = resImageUrl;
        }

        public void compare(InfraredEntity infraredEntity, InfraredT infraredT) {
            this.infraredT = infraredT;
            if ((double) infraredEntity.getAlarmMaxTemp() < infraredT.getMaxT()) {
                this.value = "1";
                this.desc = "高温告警";
            } else if ((double) infraredEntity.getWarnMaxTemp() < infraredT.getMaxT()) {
                this.value = "1";
                this.desc = "高温预警";
            }

            if ((double) infraredEntity.getAlarmMinTemp() > infraredT.getMinT()) {
                this.value = "1";
                this.desc = "低温告警";
            } else if ((double) infraredEntity.getWarnMinTemp() > infraredT.getMinT()) {
                this.value = "1";
                this.desc = "低温预警";
            }

        }

    }

    @Setter
    @Getter
    public static class Param {
        private String objectId;
        private List<InfraredResponse.Result> results;

        public Param() {
        }

        public Param(String objectId) {
            this.objectId = objectId;
        }

        public boolean addResult(InfraredResponse.Result result) {
            if (this.results == null) {
                this.results = new ArrayList();
            }

            return this.results.add(result);
        }
    }
}
