package vip.xiaonuo.coldchain.modular.app.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.coldchain.core.bean.influxdb.SensorData;
import vip.xiaonuo.coldchain.modular.app.param.AppDeviceQueryParams;
import vip.xiaonuo.coldchain.modular.app.param.SensorEchartDataResult;
import vip.xiaonuo.coldchain.modular.app.service.SimsService;
import vip.xiaonuo.common.pojo.CommonResult;

@Tag(name = "APP移动端控制器")
@RestController
@RequestMapping("/coldchain/api/sims")
@Validated
public class SimsController {
    @Autowired
    private SimsService simsService;

    @Operation(summary = "获取设备的最新的温湿度")
    @GetMapping("/{deviceCode}/{roads}")
    public CommonResult<SensorData> status(@PathVariable String deviceCode, @PathVariable Integer roads) {
        SensorData status = simsService.status(deviceCode, roads);
        return status == null ? CommonResult.data(new SensorData()) : CommonResult.data(status);
    }

    @Operation(summary = "查询采集设备数据")
    @PostMapping("/view")
    public CommonResult<SensorEchartDataResult> queryDeviceData(@RequestBody @Valid AppDeviceQueryParams appDeviceQueryParams) {
        return CommonResult.data(simsService.queryDataByDeviceIdAndRoads(appDeviceQueryParams));
    }



}