package com.gyee.wisdom.dataadapter.controller.thing;

import com.gyee.wisdom.common.data.alarm.WarningClassify;
import com.gyee.wisdom.common.data.timeseries.DoubleStatData;
import com.gyee.wisdom.common.data.timeseries.TsData;
import com.gyee.wisdom.common.data.timeseries.TsPointData;
import com.gyee.wisdom.common.data.timeseries.TsPointDataList;
import com.gyee.wisdom.common.data.windturbine.PowerStation;
import com.gyee.wisdom.common.data.windturbine.Windturbine;
import com.gyee.wisdom.dataadapter.domain.thing.StationService;
import com.gyee.wisdom.dataadapter.domain.thing.WindturbineService;
import com.gyee.wisdom.dataadapter.domain.timeseries.TsDataService;
import com.gyee.wisdom.dataadapter.domain.timeseries.TsPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/*
 *
 * @author songwb
 */


@RestController
@RequestMapping("/thing")
@CrossOrigin
public class ThingController {

    @Autowired
    protected WindturbineService windturbineService;

    @Autowired
    protected StationService stationService;

    @GetMapping("/windturbine")
    public List<Windturbine> getWindturbines(
            @RequestParam(value = "stationId", required = false) Optional<String> stationId,
            @RequestParam(value = "modelId", required = false) Optional<String> modelId
    ) {
        if (stationId.isPresent()) {
            if (modelId.isPresent()) {
                return windturbineService.queryWindturbine(stationId.get(), modelId.get());
            } else {
                return windturbineService.findByStationId(stationId.get());
            }
        } else if (modelId.isPresent()) {
            return windturbineService.findByModelId(modelId.get());
        } else {
            return windturbineService.find();
        }
    }

    @GetMapping("/windturbine/{id}")
    public Windturbine getWindturbine(
            @PathVariable("id") String wtId
    ) {
        return  windturbineService.findbyid(wtId);
    }

    @GetMapping("/station")
    public List<PowerStation> getStations() {
        return stationService.getAll();
    }

    @GetMapping("/station/{id}")
    public PowerStation getStation(
            @PathVariable("id") String stId
    ) {
        return  stationService.getStationById(stId);
    }



}


