package com.zsElectric.boot.business.controller.applet;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zsElectric.boot.business.model.form.applet.AppInvokeChargeForm;
import com.zsElectric.boot.business.model.form.applet.AppStopChargeForm;
import com.zsElectric.boot.business.model.query.applet.AppChargeOrderInfoQuery;
import com.zsElectric.boot.business.model.vo.ChargeOrderInfoVO;
import com.zsElectric.boot.business.model.vo.applet.AppChargeVO;
import com.zsElectric.boot.business.service.ChargeOrderInfoService;
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.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "充电订单相关接口")
@Slf4j
@RestController
@RequestMapping("/applet/v1/charge")
@RequiredArgsConstructor
public class AppletChargeController {

    private final ChargeOrderInfoService chargeOrderInfoService;

    /**
     * 充电订单记录
     *
     * @param queryParams
     * @return
     */
    @Operation(summary = "充电订单记录")
    @PostMapping("/getPage")
    public Result<IPage<ChargeOrderInfoVO>> getPage(@RequestBody AppChargeOrderInfoQuery queryParams) {
        IPage<ChargeOrderInfoVO> page = chargeOrderInfoService.getPage(queryParams);
        return Result.success(page);
    }

    /**
     * 启用充电
     *
     * @param formData
     * @return
     */
    @Operation(summary = "启用充电")
    @PostMapping("/invokeCharge")
    @Log(value = "启用充电", module = LogModuleEnum.APP_CHARGE_ORDER)
    public Result<AppChargeVO> invokeCharge(@Valid @RequestBody AppInvokeChargeForm formData) {
        AppChargeVO appInvokeChargeVO = chargeOrderInfoService.invokeCharge(formData);
        return Result.success(appInvokeChargeVO);
    }

    /**
     * 结束充电
     *
     * @param formData
     * @return
     */
    @Operation(summary = "结束充电")
    @PostMapping("/stopCharge")
    @Log(value = "结束充电", module = LogModuleEnum.APP_CHARGE_ORDER)
    public Result<AppChargeVO> stopCharge(@RequestBody AppStopChargeForm formData) {
        AppChargeVO appStopChargeVO= chargeOrderInfoService.stopCharge(formData);
        return Result.success(appStopChargeVO);
    }
}
