package com.starry.admin.modules.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.order.module.entity.PlayOrderRefundInfoEntity;
import com.starry.admin.modules.order.module.vo.PlayOrderRefundQueryVo;
import com.starry.admin.modules.order.module.vo.PlayOrderRefundReturnVo;
import com.starry.admin.modules.order.service.IPlayOrderRefundInfoService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 订单退款信息Controller
 *
 * @author admin
 * @since 2024-05-09
 */
@RestController
@RequestMapping("/order/refund")
public class PlayOrderRefundInfoController {
    @Resource
    private IPlayOrderRefundInfoService playOrderRefundInfoService;

    /**
     * 查询订单退款信息列表
     */
    @PostMapping("/list")
    public R list(@Validated @RequestBody PlayOrderRefundQueryVo vo) {
        IPage<PlayOrderRefundReturnVo> list = playOrderRefundInfoService.selectByPage(vo);
        return R.ok(list);
    }

    /**
     * 获取订单退款信息详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playOrderRefundInfoService.selectPlayOrderRefundInfoById(id));
    }

    /**
     * 新增订单退款信息
     */
    @Log(title = "订单退款信息", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayOrderRefundInfoEntity playOrderRefundInfo) {
        boolean success = playOrderRefundInfoService.create(playOrderRefundInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改订单退款信息
     */
    @Log(title = "订单退款信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayOrderRefundInfoEntity playOrderRefundInfo) {
        playOrderRefundInfo.setId(id);
        boolean success = playOrderRefundInfoService.update(playOrderRefundInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除订单退款信息
     */
    @Log(title = "订单退款信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playOrderRefundInfoService.deletePlayOrderRefundInfoByIds(ids));
    }
}
