package com.zsElectric.boot.charging.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.zsElectric.boot.charging.dto.StartChargingRequestDTO;
import com.zsElectric.boot.charging.dto.StartChargingResponseVO;
import com.zsElectric.boot.charging.service.ChargingBusinessService;
import com.zsElectric.boot.charging.vo.*;
import com.zsElectric.boot.common.annotation.Log;
import com.zsElectric.boot.common.enums.LogModuleEnum;
import com.zsElectric.boot.core.web.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequiredArgsConstructor
@Tag(name = "充电业务相关接口")
@RequestMapping("/dev/v1/business")
public class ChargingBusinessController {

    private final ChargingBusinessService chargingBusinessService;

    /**
     * <p>查询业务策略信息</p>
     * @author SheepHy
     * @param EquipBizSeq  设备业务流水号
     * @param ConnectorID 充电设备接口编码
     * @return 返回值描述，如无返回值则为void 返回值为类则包含{@link ChargingPricePolicyVO}
     *
     */
    @Operation(summary = "查询业务策略信息")
    @GetMapping("/query_equip_business_policy")
    @Log(value = "查询业务策略信息", module = LogModuleEnum.PARKING_CALL, params = true, result = true)
    public Result<ChargingPricePolicyVO> queryEquipBusinessPolicy(@RequestParam("EquipBizSeq") @Schema(description = "设备业务流水号", example = "123456789123456789123456789") String EquipBizSeq,
                                                                   @RequestParam("ConnectorID") @Schema(description = "充电设备接口编码") String ConnectorID) throws Exception{
        return Result.success(chargingBusinessService.queryEquipBusinessPolicy(EquipBizSeq, ConnectorID));
    }

    /**
     * <p>请求设备认证</p>
     * @author SheepHy
     * @param EquipAuthSeq 设备认证流水号
     * @param ConnectorID 充电设备接口编码
     * @return 返回值描述，如无返回值则为void 返回值为类则包含{@link EquipmentAuthResponseVO}
     *
     */
    @Operation(summary = "请求设备认证")
    @GetMapping("/query_equip_auth")
    @Log(value = "请求设备认证", module = LogModuleEnum.PARKING_CALL, params = true, result = true)
    public Result<EquipmentAuthResponseVO> queryEquipAuth(String EquipAuthSeq, String ConnectorID) throws JsonProcessingException {
        return Result.success(chargingBusinessService.queryEquipAuth(EquipAuthSeq, ConnectorID));
    }

    /**
     * <p>查询充电站信息</p>
     * @author wzq
     * @param LastQueryTime 最后一次查询时间
     * @param PageNo 页码
     * @param PageSize 页大小
     * @return 充电站信息列表
     *
     */
    @Operation(summary = "查询充电站信息")
    @GetMapping("/query_stations_info")
    @Log(value = "查询充电站信息", module = LogModuleEnum.PARKING_CALL, params = true, result = true)
    public Result<QueryStationsInfoVO> queryStationsInfo(@RequestParam(value = "LastQueryTime", required = false) @Schema(description = "最后一次查询时间") String LastQueryTime,
                                                         @RequestParam(value = "PageNo",defaultValue = "1") @Schema(description = "页码") Integer PageNo,
                                                         @RequestParam(value = "PageSize", defaultValue = "10") @Schema(description = "页大小") Integer PageSize) throws Exception {
        return Result.success(chargingBusinessService.queryStationsInfo(LastQueryTime, PageNo, PageSize));
    }

    /**
     * <p>设备接口状态查询</p>
     * @author wzq
     * @param stationIDs 充电站ID列表
     * @return 设备接口状态
     *
     */
    @Operation(summary = "设备接口状态查询")
    @PostMapping("/query_station_status")
    @Log(value = "设备接口状态查询", module = LogModuleEnum.PARKING_CALL, params = true, result = true)
     public Result<QueryStationStatusVO> queryStationStatus(@RequestBody List<String> stationIDs) throws JsonProcessingException {
        return Result.success(chargingBusinessService.queryStationStatus(stationIDs));
     }


    /**
     * <p>请求启动充电</p>
     * @author SheepHy
     * @param requestDTO，参数为类则包含{@link StartChargingRequestDTO}
     * @return 返回值描述，如无返回值则为void 返回值为类则包含{@link StartChargingResponseVO}
     */
    @Operation(summary = "请求启动充电")
    @PostMapping("/query_start_charge")
    @Log(value = "请求启动充电", module = LogModuleEnum.PARKING_CALL, params = true, result = true)
    public Result<StartChargingResponseVO> startCharging(@RequestBody StartChargingRequestDTO requestDTO) throws JsonProcessingException {
        return Result.success(chargingBusinessService.startCharging(requestDTO));
    }

    /**
     * <p>查询充电状态</p>
     * @author SheepHy
     */
    @Operation(summary = "查询充电状态")
    @PostMapping("/query_equip_charge_status")
    @Log(value = "查询充电状态", module = LogModuleEnum.PARKING_CALL, params = true, result = true)
    public Result<ChargingStatusQueryResponseVO> queryChargingStatus(@RequestParam("StartChargeSeq") @Schema(description = "充电订单号(格式:运营商ID+唯一编号)") String StartChargeSeq) throws JsonProcessingException {
        return Result.success(chargingBusinessService.queryChargingStatus(StartChargeSeq));
    }

    /**
     * <p>请求停止充电</p>
     * @author SheepHy
     */
    @Operation(summary = "请求停止充电")
    @GetMapping("/query_stop_charge")
    @Log(value = "请求停止充电", module = LogModuleEnum.PARKING_CALL, params = true, result = true)
    public Result<StopChargingOperationResponseVO> stopCharging(@RequestParam("StartChargeSeq") @Schema(description = "充电订单号(格式:运营商ID+唯一编号)") String StartChargeSeq,
                                                                @RequestParam("ConnectorID") @Schema(description = "充电设备接口编码") String ConnectorID) throws JsonProcessingException {
        return Result.success(chargingBusinessService.stopCharging(StartChargeSeq, ConnectorID));
    }
}
