package com.zsElectric.boot.business.controller;

import com.zsElectric.boot.business.service.UserRefundsOrderInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zsElectric.boot.business.model.form.UserRefundsOrderInfoForm;
import com.zsElectric.boot.business.model.query.UserRefundsOrderInfoQuery;
import com.zsElectric.boot.business.model.vo.UserRefundsOrderInfoVO;
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 16:48
 */
@Tag(name = "退款订单接口")
@RestController
@RequestMapping("/api/v1/user-refunds-order-info")
@RequiredArgsConstructor
public class UserRefundsOrderInfoController  {

    private final UserRefundsOrderInfoService userRefundsOrderInfoService;

    @Operation(summary = "退款订单分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('business:user-refunds-order-info:query')")
    public PageResult<UserRefundsOrderInfoVO> getUserRefundsOrderInfoPage(UserRefundsOrderInfoQuery queryParams ) {
        IPage<UserRefundsOrderInfoVO> result = userRefundsOrderInfoService.getUserRefundsOrderInfoPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "获取退款订单表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('business:user-refunds-order-info:edit')")
    public Result<UserRefundsOrderInfoForm> getUserRefundsOrderInfoForm(
        @Parameter(description = "退款订单ID") @PathVariable Long id
    ) {
        UserRefundsOrderInfoForm formData = userRefundsOrderInfoService.getUserRefundsOrderInfoFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改退款订单")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('business:user-refunds-order-info:edit')")
    public Result<Void> updateUserRefundsOrderInfo(
            @Parameter(description = "退款订单ID") @PathVariable Long id,
            @RequestBody @Validated UserRefundsOrderInfoForm formData
    ) {
        boolean result = userRefundsOrderInfoService.updateUserRefundsOrderInfo(id, formData);
        return Result.judge(result);
    }

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