package org.dromara.pay.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.pay.domain.bo.PayRefundBo;
import org.dromara.pay.domain.vo.PayRefundVo;
import org.dromara.pay.service.PayRefundService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 退款订单
 *
 * @author pengles
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pay/refund")
public class PayRefundController extends BaseController {

    private final PayRefundService payRefundService;

    /**
     * 查询退款订单列表
     */
    @SaCheckPermission("pay:refund:list")
    @GetMapping("/list")
    public TableDataInfo<PayRefundVo> list(PayRefundBo bo, PageQuery pageQuery) {
        return payRefundService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取退款订单详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("pay:refund:query")
    @GetMapping("/{id}")
    public R<PayRefundVo> getInfo(@PathVariable Long id) {
        return R.ok(payRefundService.queryById(id));
    }

    /**
     * 新增退款订单
     */
    @SaCheckPermission("pay:refund:add")
    @Log(title = "退款订单", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody PayRefundBo bo) {
        return toAjax(payRefundService.insertByBo(bo));
    }

    /**
     * 修改退款订单
     */
    @SaCheckPermission("pay:refund:edit")
    @Log(title = "退款订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody PayRefundBo bo) {
        return toAjax(payRefundService.updateByBo(bo));
    }

    /**
     * 删除退款订单
     *
     * @param ids 主键串
     */
    @SaCheckPermission("pay:refund:remove")
    @Log(title = "退款订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        return toAjax(payRefundService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
