package com.ruoyi.web.controller.app;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.refund.domain.Refund;
import com.ruoyi.ss.refund.domain.RefundBO;
import com.ruoyi.ss.refund.domain.RefundDTO;
import com.ruoyi.ss.refund.domain.RefundQuery;
import com.ruoyi.ss.refund.service.IRefundService;
import com.ruoyi.ss.refund.service.IRefundValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 退款订单Controller
 *
 * @author 邱贞招
 * @date 2024-05-10
 */
@RestController
@RequestMapping("/app/refund")
public class AppRefundController extends BaseController
{
    @Autowired
    private IRefundService etRefundService;

    @Resource
    private IRefundValidator refundValidator;

    /**
     * 查询退款订单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RefundQuery etRefund)
    {
        startPage();
        List<Refund> list = etRefundService.selectEtRefundListWithIsolate(etRefund);
        return getDataTable(list);
    }

    /**
     * 获取退款订单详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(etRefundService.selectEtRefundById(id));
    }

    /**
     * 退款
     */
    @Log(title = "退款", businessType = BusinessType.REFUND)
    @PostMapping
    public AjaxResult refund(@RequestBody RefundDTO dto)
    {
        logger.info("退款:dto=【{}】", dto);
        RefundBO bo = refundValidator.preRefund(dto);
        return toAjax(etRefundService.refund(bo));
    }



//    /**
//     * 修改退款订单
//     */
//    @Log(title = "退款订单", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody Refund etRefund)
//    {
//        return toAjax(etRefundService.updateEtRefund(etRefund));
//    }

//    /**
//     * 删除退款订单
//     */
//    @Log(title = "退款订单", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(etRefundService.deleteEtRefundByIds(ids));
//    }

//    /**
//     * 同意退款
//     */
//    @Log(title = "同意退款", businessType = BusinessType.PASS)
//    @PostMapping("/pass")
//    public AjaxResult pass(String refundNo){
//        return toAjax(etRefundService.passRefund(refundNo));
//    }
//
//    /**
//     * 拒绝退款
//     */
//    @Log(title = "拒绝退款", businessType = BusinessType.REJECT)
//    @PostMapping("/reject")
//    public AjaxResult reject(String refundNo){
//        return toAjax(etRefundService.reject(refundNo));
//    }
}
