package cn.iocoder.yudao.module.product.controller.app.envdata;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.controller.admin.envdata.vo.EnvDataRespVO;
import cn.iocoder.yudao.module.product.controller.admin.envtype.vo.EnvTypeDeviceConfigRespVO;
import cn.iocoder.yudao.module.product.service.envdata.EnvDataService;
import cn.iocoder.yudao.module.product.service.envtype.EnvTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;

@Api(tags = "APP移动端 - 环境数据")
@RestController
@RequestMapping("/product/env-data")
@Validated
public class EnvDataAppController {

    @Resource
    private EnvDataService envDataService;

    @Resource
    private EnvTypeService envTypeService;

    @GetMapping("/getLastEnvDatas")
    @PermitAll // 无需登陆
    @ApiOperation("获得最后(最新)的环境数据")
    @ApiImplicitParam(name = "landId", value = "地块编码", required = true, example = "AECD202305041501UE6F", dataTypeClass = String.class)
    public CommonResult<List<EnvDataRespVO>> getLastEnvDatas(@RequestParam("landId") String landId) {
        return CommonResult.success(envDataService.gatLastEnvDatas(landId));
    }

    @GetMapping("/getAVGEnvDatas")
    @PermitAll // 无需登陆
    @ApiOperation("获得N天内环境数据的均值")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "landId", value = "地块编码", required = true, example = "AECD202305041501UE6F", dataTypeClass = String.class),
        @ApiImplicitParam(name = "day", value = "最近X天", example = "7", dataTypeClass = Integer.class)
    })
    public CommonResult<List<EnvDataRespVO>> getAVGEnvDatas(@RequestParam("landId") String landId, @RequestParam("day") Integer day) {
        return CommonResult.success(envDataService.getAVGEnvDatas(landId, day, null));
    }

    @GetMapping("/getEnvTypeConfig")
    @PermitAll // 无需登陆
    @ApiOperation("获得环境类型配置数据")
    @ApiImplicitParam(name = "businessInfoId", value = "商户ID", example = "1", dataTypeClass = Long.class)
    public CommonResult<List<EnvTypeDeviceConfigRespVO>> getEnvTypeConfig(@RequestParam("businessInfoId") Long businessInfoId) {
        return CommonResult.success(envTypeService.getEnvTypeConfigGroupByLandId(businessInfoId));
    }

}
