package cn.lihongjie.coal.emDevice.client;

import feign.Headers;
import feign.Param;
import feign.RequestLine;

import org.apache.commons.lang3.ObjectUtils;

import java.util.*;

public interface DustApi {

    @RequestLine("GET /api/getTokenByAcc?loginName={loginName}&password={password}")
    GetTokenResponse getToken(
            @Param("loginName") String loginName, @Param("password") String password);

    @RequestLine("GET /api/data/getRealtimeData?deviceIds={deviceIds}")
    @Headers("token: {token}")
    GetRealtimeDataResponse getRealtimeData(@Param("token") String token,  @Param("deviceIds") String deviceId);

    @RequestLine("GET /api/data/getHistoryData?deviceId={deviceId}&beginTime={beginTime}&endTime={endTime}")
    @Headers("token: {token}")

    GetRealtimeDataResponse getHistoryData(@Param("token") String token, @Param("deviceId") String deviceId, @Param("beginTime") String beginTime, @Param("endTime") String endTime);

    record BaseResponse(String code, String message) {}

    record GetTokenData(String token, String expiration) {}

    /**
     * { "deviceId": "22005373", "status": "offline", "pm25": null, "pm10": null, "noise": null,
     * "tem": null, "hum": null, "wp": null, "ws": null, "wd8": null, "wd360": null, "tsp": null,
     * "atm": null, "lux": null, "co": null, "so2": null, "no2": null, "o3": null, "r1": 0, "r2": 0,
     * "r3": 0, "r4": 0, "r5": 0, "r6": 0, "r7": 0, "r8": 0, "alarmInfos": [] }
     */
    record DeviceData(
            String deviceId,
            String status,
            Double pm25,
            Double pm10,
            Double noise,
            Double tem,
            Double hum,
            Double wp,
            Double ws,
            Double wd8,
            Double wd360,
            Double tsp,
            Double atm,
            Double lux,
            Double co,
            Double so2,
            Double no2,
            Double o3,
            Integer r1,
            Integer r2,
            Integer r3,
            Integer r4,
            Integer r5,
            Integer r6,
            Integer r7,
            Integer r8,
            String recordId,
            String recordTime,
            String strtime


    ) {
        public boolean notEmpty() {
            return !ObjectUtils.allNull(pm25
                            ,pm10
                            ,noise
                            ,tem
                            ,hum
                            ,wp
                            ,ws
                            ,wd8
                            ,wd360
                            ,tsp
                            ,atm
                            ,lux
                            ,co
                            ,so2
                            ,no2
                    ,o3);
        }
    }

    record GetTokenResponse(String code, String message, GetTokenData data) {}

    record GetRealtimeDataResponse(String code, String message, List<DeviceData> data) {}

}
