package com.kym.admin.controller;

import com.alibaba.fastjson2.JSONObject;
import com.kym.common.R;
import com.kym.common.annotation.SysLog;
import com.kym.entity.admin.Station;
import com.kym.entity.admin.queryParams.StationQueryParam;
import com.kym.service.admin.StationService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 充电站信息 前端控制器
 * </p>
 *
 * @author skyline
 * @since 2023-08-12
 */
@RestController
@RequestMapping("/station")
public class StationController {

    private final StationService stationService;


    public StationController(StationService stationService) {
        this.stationService = stationService;
    }

    @SysLog("充电站数据统计")
    @GetMapping("/stationStatusDetail")
    R<?> stationStatusDetail(@RequestParam("stationId") String stationId,
                             @RequestParam("startTime") @DateTimeFormat(pattern = "yyyy-MM-dd") String startTime,
                             @RequestParam("endTime") @DateTimeFormat(pattern = "yyyy-MM-dd") String endTime) {
        // 请求en+接口
        var response = stationService.stationStats(stationId, startTime, endTime);
        return R.success(response);
    }

    @SysLog("站点列表")
    @GetMapping("listStation")
    R<?> listStation(@ModelAttribute StationQueryParam params) {
        return R.success(stationService.listStation(params));
    }


    /**
     * 站点列表，管理后台配置使用
     * @return
     */
    @SysLog("站点列表")
    @GetMapping("list")
    R<?> list() {
        return R.success(stationService.list());
    }



    @SysLog("修改站点信息")
    @PostMapping("modify")
    R<?> modifyStation(@RequestBody Station station) {
        stationService.modifyStation(station);
        return R.success();
    }

    /**
     * 拉取EN+充电站信息数据并更新本地服务器数据
     *
     * @return
     */
    @GetMapping("/pullEnStations/{stationId}")
    R<?> pullEnStationInfos(@PathVariable String stationId) {
        stationService.pullEnStationInfos(stationId);
        return R.success();
    }

    @PostMapping("/importStation")
    R<?> importStation(@RequestBody JSONObject data) {
        stationService.importStation(data);
        return R.success(data);
    }

}
