package com.gyee.runeconomy.feign;

import com.gyee.runeconomy.model.PointData;
import com.gyee.runeconomy.util.realtimesource.timeseries.DoubleStatData;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.net.URI;
import java.util.List;
import java.util.Map;

@FeignClient("adapter")
public interface AdapterApi {
    @GetMapping("/latest2")
    List<PointData> getLatest2(URI baseUri, @RequestParam("keys") String keys);

//    @GetMapping("/latest")
//    Map<String, PointData> getLatest(URI baseUri, @RequestParam("keys") String keys);

    @PostMapping("/latest")
//    @Headers("Content-Type: application/json; charset=UTF-8")
    Map<String, PointData> getLatest(URI baseUri, @RequestBody String keys);

    @GetMapping("/history/snap")
    List<PointData> getHistorySnap(URI baseUri, @RequestParam("tagName") String tagName,
                                   @RequestParam("startTs") long startTs,
                                   @RequestParam("endTs") long endTs,
                                   @RequestParam("interval") int interval);

    @GetMapping("/history/raw")
    List<PointData> getHistoryRaw(URI baseUri, @RequestParam("tagName") String tagName,
                                  @RequestParam("startTs") long startTs,
                                  @RequestParam("endTs") long endTs);

    @GetMapping("/history/stat2")
    DoubleStatData getHistoryStat(URI baseUri, @RequestParam("tagName") String tagName,
                                  @RequestParam("startTs") long startTs,
                                  @RequestParam("endTs") long endTs);
    //@RequestParam("interval") int interval);

    @GetMapping("/history/stat")
    List<DoubleStatData> getHistoryStat2(URI baseUri, @RequestParam("tagName") String tagName,
                                         @RequestParam("startTs") long startTs,
                                         @RequestParam("endTs") long endTs,
                                         @RequestParam("interval") int interval);

//    @GetMapping("/history/section")
//    Map<String, PointData> getHistorySection(URI baseUri, @RequestParam("tagNames") String tagNames,
//                                             @RequestParam("ts") long ts);

    @PostMapping("/history/section")
    Map<String, PointData> getHistorySection(URI baseUri, @RequestBody String tagNames,
                                              @RequestParam("ts") long ts);

    @GetMapping("/history/section2")
    List<PointData> getHistorySection2(URI baseUri, @RequestParam("tagName") String tagName,
                                       @RequestParam("ts") long ts);

//    @PostMapping("/latest2")
//    Boolean writeHistory(URI baseUri, @RequestBody PointData tsData);
//
//    @PostMapping("/latest2/batch")
//    Boolean writeHistoryBatch(URI baseUri, @RequestBody List<PointData> tsData);

    @PostMapping("/save")
    Boolean writeHistory(URI baseUri, @RequestBody PointData tsData);

    @PostMapping("/save/batch")
    Boolean writeHistoryBatch(URI baseUri, @RequestBody List<PointData> tsData);
}
