package com.leromro.core.controller;

import java.util.List;

import com.leromro.core.domain.MainOrders;
import com.leromro.core.domain.vo.OrderRefundVO;
import com.leromro.core.domain.vo.WebOrderRefundVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.leromro.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.leromro.common.annotation.Log;
import com.leromro.common.core.controller.BaseController;
import com.leromro.common.core.domain.AjaxResult;
import com.leromro.common.enums.BusinessType;
import com.leromro.core.domain.OrderRefund;
import com.leromro.core.service.IOrderRefundService;
import com.leromro.common.core.page.TableDataInfo;

/**
 * 订单取消/退款Controller
 * 
 * @author ruoyi
 * @date 2025-04-21
 */
@RestController
@Api(tags = "订单取消,退款")
@RequestMapping("/core/users/refund")
public class OrderRefundController extends BaseController
{
    @Autowired
    private IOrderRefundService lOrderRefundService;

    /**
     * 查询订单取消/退款列表
     */
/*    @ApiOperation(value ="查询 ", notes = "订单取消/退款列表")
    *//*@PreAuthorize("@ss.hasPermi('core:refund:list')")*//*
    @GetMapping("/list")
    public TableDataInfo<OrderRefund> list(OrderRefund orderRefund)
    {
        startPage();
        List<OrderRefund> list = lOrderRefundService.selectLOrderRefundList(orderRefund);
        return getDataTable(list);
    }*/
    @ApiOperation(value ="web端 退款列表", notes = "传入分页参数")
    @GetMapping("web/list")
    public TableDataInfo<WebOrderRefundVO> refundList(MainOrders mainOrders){
        startPage();;
        List<WebOrderRefundVO> list = lOrderRefundService.selectWebOrderRefundList(mainOrders);
        return getDataTable(list);
    }


    /**
     * 导出订单取消/退款列表
     */
    /*@ApiOperation("导出订单取消/退款列表")
    @PreAuthorize("@ss.hasPermi('core:refund:export')")
    @Log(title = "订单取消/退款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderRefund orderRefund)
    {
        List<OrderRefund> list = lOrderRefundService.selectLOrderRefundList(orderRefund);
        ExcelUtil<OrderRefund> util = new ExcelUtil<OrderRefund>(OrderRefund.class);
        util.exportExcel(response, list, "订单取消/退款数据");
    }*/

    /**
     * 获取订单取消/退款详细信息
     */
    @ApiOperation(value =" web 获取 订单取消/退款详细信息", notes = "传入路径参数，退款单号id")
    /*@PreAuthorize("@ss.hasPermi('core:refund:query')")*/
    @GetMapping(value = "/refundInfo/{orderRefundId}")
    public R<OrderRefund> getInfo(@PathVariable("orderRefundId") Long orderRefundId)
    {
        return R.ok(lOrderRefundService.selectLOrderRefundByOrderRefundId(orderRefundId));
    }

    /**
     * 获取订单取消/退款详细信息
     */
    @ApiOperation(value =" 小程序端 订单取消/退款信息 回显 ", notes = "传入主订单id")
    /*@PreAuthorize("@ss.hasPermi('core:refund:query')")*/
    @GetMapping(value = "/orderInfo/{mainOrderId}")
    public R<OrderRefundVO> getRefundIdInfo(@PathVariable("mainOrderId") Long mainOrderId)
    {
        return R.ok(lOrderRefundService.selectOrderRefundByMainOrderId(mainOrderId));
    }

    /**
     * 新增订单取消/退款
     */
    @ApiOperation(value ="小程序端 新增订单取消/退款 传入主订单id，退款图片以及原因")
/*    @PreAuthorize("@ss.hasPermi('core:refund:add')")*/
   /* @Log(title = "新增订单取消/退款  ", businessType = BusinessType.INSERT)*/
    @PostMapping("/newOrderRefund")
    public AjaxResult add(@RequestBody OrderRefund orderRefund)
    {
        return lOrderRefundService.insertLOrderRefund(orderRefund);
    }

    /**
     * 修改订单取消/退款
     */
 /*   @ApiOperation(value ="修改订单取消/退款", notes = "传入分页参数")
   *//* @PreAuthorize("@ss.hasPermi('core:refund:edit')")*//*
    *//*@Log(title = "修改订单取消/退款", businessType = BusinessType.UPDATE)*//*
    @PutMapping("/updateRefund")
    public AjaxResult edit(@RequestBody OrderRefund orderRefund)
    {
        return toAjax(lOrderRefundService.updateLOrderRefund(orderRefund));
    }*/

    /**
     * 删除订单取消/退款
     */
/*    @ApiOperation( value ="删除订单取消/退款", notes = "传入id数组，批量删除")
   *//* @PreAuthorize("@ss.hasPermi('core:refund:remove')")*//*
   *//* @Log(title = "删除订单取消/退款", businessType = BusinessType.DELETE)*//*
	@DeleteMapping("/{orderRefundIds}")
    public R<Integer> remove(@PathVariable Long[] orderRefundIds)
    {
        return R.ok(lOrderRefundService.deleteLOrderRefundByOrderRefundIds(orderRefundIds));
    }*/
    /**
     * 审批通过订单退款 以及后续流程。
     */
    @ApiOperation(value = "web端 订单退款审批接口传入mainOrderId  orderRefundId refundAmount 状态", notes = "传入mainOrderId  orderRefundId refundAmount 还有状态")
   /* @PreAuthorize("@ss.hasPermi('core:refund:remove')")*/
  /*  @Log(title = "订单退款 审批", businessType = BusinessType.UPDATE)*/
	@PostMapping("/checkOrderRefund")
    public AjaxResult checkOrderRefund(@RequestBody OrderRefund orderRefund)
    {

        return lOrderRefundService.checkOrderRefund(orderRefund);
    }


}
