package com.zsElectric.boot.business.controller;

import com.zsElectric.boot.business.service.UserOrderInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zsElectric.boot.business.model.form.UserOrderInfoForm;
import com.zsElectric.boot.business.model.query.UserOrderInfoQuery;
import com.zsElectric.boot.business.model.vo.UserOrderInfoVO;
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-16 16:25
 */
@Tag(name = "用户支付订单信息接口")
@RestController
@RequestMapping("/api/v1/user-order-info")
@RequiredArgsConstructor
public class UserOrderInfoController {

    private final UserOrderInfoService userOrderInfoService;

    @Operation(summary = "用户支付订单信息分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('business:user-order-info:query')")
    public PageResult<UserOrderInfoVO> getUserOrderInfoPage(UserOrderInfoQuery queryParams) {
        IPage<UserOrderInfoVO> result = userOrderInfoService.getUserOrderInfoPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增用户支付订单信息")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('business:user-order-info:add')")
    public Result<Void> saveUserOrderInfo(@RequestBody @Valid UserOrderInfoForm formData) {
        boolean result = userOrderInfoService.saveUserOrderInfo(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取用户支付订单信息表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('business:user-order-info:edit')")
    public Result<UserOrderInfoForm> getUserOrderInfoForm(
            @Parameter(description = "用户支付订单信息ID") @PathVariable Long id
    ) {
        UserOrderInfoForm formData = userOrderInfoService.getUserOrderInfoFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改用户支付订单信息")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('business:user-order-info:edit')")
    public Result<Void> updateUserOrderInfo(
            @Parameter(description = "用户支付订单信息ID") @PathVariable Long id,
            @RequestBody @Validated UserOrderInfoForm formData
    ) {
        boolean result = userOrderInfoService.updateUserOrderInfo(id, formData);
        return Result.judge(result);
    }

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