package com.mall.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.common.domain.vo.result.Result;
import com.mall.common.domain.vo.result.ResultCodeEnum;
import com.mall.order.domain.dto.PaymentInfoDto;
import com.mall.order.domain.entity.PaymentInfo;
import com.mall.order.domain.vo.PaymentInfoVo;
import com.mall.order.service.PaymentInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 支付信息表 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-05 18:54:06
 */
@Tag(name = "支付信息表", description = "支付信息表相关接口")
@RestController
@RequestMapping("/api/order/payment-info")
@RequiredArgsConstructor
public class PaymentInfoController {

    private final PaymentInfoService paymentInfoService;

    @Operation(summary = "分页查询支付信息表", description = "分页支付信息表")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<PaymentInfoVo>> getPaymentInfoPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            PaymentInfoDto dto) {
        Page<PaymentInfo> pageParams = new Page<>(page, limit);
        PageResult<PaymentInfoVo> pageResult = paymentInfoService.getPaymentInfoPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加支付信息表", description = "添加支付信息表")
    @PostMapping()
    public Result<String> addPaymentInfo(@Valid @RequestBody PaymentInfoDto dto) {
        paymentInfoService.addPaymentInfo(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新支付信息表", description = "更新支付信息表")
    @PutMapping()
    public Result<String> updatePaymentInfo(@Valid @RequestBody PaymentInfoDto dto) {
        paymentInfoService.updatePaymentInfo(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除支付信息表", description = "删除支付信息表")
    @DeleteMapping()
    public Result<String> deletePaymentInfo(@RequestBody List<Long> ids) {
        paymentInfoService.deletePaymentInfo(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}