package com.zsElectric.boot.business.controller;

import com.zsElectric.boot.business.service.ChargeOrderInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zsElectric.boot.business.model.form.ChargeOrderInfoForm;
import com.zsElectric.boot.business.model.query.ChargeOrderInfoQuery;
import com.zsElectric.boot.business.model.vo.ChargeOrderInfoVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zsElectric.boot.core.web.PageResult;
import com.zsElectric.boot.core.web.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 充电订单信息前端控制层
 *
 * @author zsElectric
 * @since 2025-12-17 19:13
 */
@Tag(name = "充电订单信息接口")
@RestController
@RequestMapping("/api/v1/charge-order-info")
@RequiredArgsConstructor
public class ChargeOrderInfoController  {

    private final ChargeOrderInfoService chargeOrderInfoService;

    @Operation(summary = "充电订单信息分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('business:charge-order-info:query')")
    public PageResult<ChargeOrderInfoVO> getChargeOrderInfoPage(ChargeOrderInfoQuery queryParams ) {
        IPage<ChargeOrderInfoVO> result = chargeOrderInfoService.getChargeOrderInfoPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "获取充电订单信息表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('business:charge-order-info:edit')")
    public Result<ChargeOrderInfoForm> getChargeOrderInfoForm(
        @Parameter(description = "充电订单信息ID") @PathVariable Long id
    ) {
        ChargeOrderInfoForm formData = chargeOrderInfoService.getChargeOrderInfoFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改充电订单信息")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('business:charge-order-info:edit')")
    public Result<Void> updateChargeOrderInfo(
            @Parameter(description = "充电订单信息ID") @PathVariable Long id,
            @RequestBody @Validated ChargeOrderInfoForm formData
    ) {
        boolean result = chargeOrderInfoService.updateChargeOrderInfo(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除充电订单信息")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('business:charge-order-info:delete')")
    public Result<Void> deleteChargeOrderInfos(
        @Parameter(description = "充电订单信息ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = chargeOrderInfoService.deleteChargeOrderInfos(ids);
        return Result.judge(result);
    }
}
