package com.rehome.jpahefengweather.controller;


import com.rehome.jpahefengweather.dto.*;
import com.rehome.jpahefengweather.entity.HefengCity;
import com.rehome.jpahefengweather.entity.NowWeather;
import com.rehome.jpahefengweather.service.CityService;
import com.rehome.jpahefengweather.service.HefengWeatherService;
import com.rehome.jpahefengweather.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/hefengWeather/service")
public class HefengWeatherController {

    @Resource
    private CityService cityService;
    @Resource
    private HefengWeatherService hefengWeatherService;

    /**
     * @date 2022-05-01 14:42
     * @description: 获取支持天气查询的城市
     * @Param:
     */
    @GetMapping("/getCityList")
    public Result<List<HefengCity>> getCityList(){
        return Result.of(this.cityService.findAllCity());
    }

    //region 获取历史天气
    @PostMapping("/getNowWeatherEntity")
//    @ApiOperation(value = "获取历史天气数据", notes = "获取历史天气数据")
//    @ApiImplicitParams(value = {
//            @ApiImplicitParam(name = "dto", value = "获取历史天气处理", dataTypeClass = BaseWeatherFindDto.class, paramType = "body", required = true),
//    })
    public Result<List<NowWeather>> getNowWeatherEntity(@Validated @RequestBody BaseWeatherFindDto dto){
        List<NowWeather> weathers = this.hefengWeatherService.findNowWeatherByLocationIdAndDate(dto.getLocationId(),dto.getWeatherDate());
        return Result.of(weathers);
    }
    //endregion
    //region 获取历史天气
    @PostMapping("/getNowWeatherDto")
//    @ApiOperation(value = "获取历史天气数据", notes = "获取历史天气数据")
//    @ApiImplicitParams(value = {
//            @ApiImplicitParam(name = "dto", value = "获取历史天气处理", dataTypeClass = BaseWeatherFindDto.class, paramType = "body", required = true),
//    })
    public Result<List<NowWeatherDto>> getNowWeatherDto(@Validated @RequestBody BaseWeatherFindDto dto){
        List<NowWeatherDto> weathers = this.hefengWeatherService.findHistoryWeatherByLocationIdAndDateDto(dto.getLocationId(),dto.getWeatherDate());
        return Result.of(weathers);
    }
    //endregion
    //region 获取实时天气
    @PostMapping("/getNowWeatherDtoOne")
//    @ApiOperation(value = "获取实时天气数据", notes = "获取实时天气数据")
//    @ApiImplicitParams(value = {
//            @ApiImplicitParam(name = "dto", value = "实时天气数据处理", dataTypeClass = BaseFindDto.class, paramType = "body", required = true),
//    })
    public Result<NowWeatherDto> getNowWeatherDtoOne(@Validated @RequestBody BaseFindDto dto){
        NowWeatherDto nowWeatherDto=this.hefengWeatherService.findNowWeatherByLocationIdAndDateDto(dto.getLocationId());
        return Result.of(nowWeatherDto);
    }
    //endregion
    //region 获取历史天气
    @PostMapping("/getForecastWeatherDto")
//    @ApiOperation(value = "获取天气预报数据", notes = "获取天气预报数据")
//    @ApiImplicitParams(value = {
//            @ApiImplicitParam(name = "dto", value = "天气预报处理", dataTypeClass = BaseWeatherFindDto.class, paramType = "body", required = true),
//    })
    public Result<List<ForecastWeatherDto>> getForecastWeatherDto(@Validated @RequestBody BaseWeatherFindDto dto){
        List<ForecastWeatherDto> weathers = this.hefengWeatherService.findForecastWeatherByLocationIdAndDateDto(dto.getLocationId(),dto.getWeatherDate());
        return Result.of(weathers);
    }
    //endregion
    //region 获取本地保存的和风天气平台，实时天气和天气预报
    @PostMapping("/getHefengWeatherResultDtoByLocationIdAndDateDto")
//    @ApiOperation(value = "获取本地保存的和风天气平台，实时天气和天气预报", notes = "获取本地保存的和风天气平台，实时天气和天气预报")
//    @ApiImplicitParams(value = {
//            @ApiImplicitParam(name = "dto", value = "天气预报处理", dataTypeClass = BaseWeatherFindDto.class, paramType = "body", required = true),
//    })
    public HefengWeatherResultDto getHefengWeatherResultDtoByLocationIdAndDateDto(@Validated @RequestBody BaseWeatherFindDto dto){
        HefengWeatherResultDto hefengWeatherResultDto = this.hefengWeatherService.getHefengWeatherResultDtoByLocationIdAndDateDto(dto.getLocationId(),dto.getWeatherDate());
        return hefengWeatherResultDto;
    }
    //endregion
    //region 获取本地保存的和风天气平台，实时天气和天气预报
    @PostMapping("/getHefengWeatherResultDtoByLocationId")
//    @ApiOperation(value = "获取本地保存的和风天气平台，实时天气和天气预报", notes = "获取本地保存的和风天气平台，实时天气和天气预报")
//    @ApiImplicitParams(value = {
//            @ApiImplicitParam(name = "dto", value = "天气预报处理", dataTypeClass = BaseFindDto.class, paramType = "body", required = true),
//    })
    public HefengWeatherResultDto getHefengWeatherResultDtoByLocationId(@Validated @RequestBody BaseFindDto dto){
        String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        HefengWeatherResultDto hefengWeatherResultDto = this.hefengWeatherService.getHefengWeatherResultDtoByLocationIdAndDateDto(dto.getLocationId(),currentDate);
        return hefengWeatherResultDto;
    }
    //endregion
}