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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.order.module.entity.PlayOrderComplaintInfoEntity;
import com.starry.admin.modules.order.module.vo.PlayOrderComplaintQueryVo;
import com.starry.admin.modules.order.module.vo.PlayOrderComplaintReturnVo;
import com.starry.admin.modules.order.service.IPlayOrderComplaintInfoService;
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-07
 */
@RestController
@RequestMapping("/order/complaint")
public class PlayOrderComplaintInfoController {
    @Resource
    private IPlayOrderComplaintInfoService playOrderComplaintInfoService;

    /**
     * 查询订单投诉信息列表
     */
    @PostMapping("/listByPage")
    public R list(@Validated @RequestBody PlayOrderComplaintQueryVo vo) {
        IPage<PlayOrderComplaintReturnVo> list = playOrderComplaintInfoService.selectByPage(vo);
        return R.ok(list);
    }

    /**
     * 获取订单投诉信息详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playOrderComplaintInfoService.selectPlayOrderComplaintInfoById(id));
    }

    /**
     * 新增订单投诉信息
     */
    //@PreAuthorize("@customSs.hasPermission('order:complaint:add')")
    @Log(title = "订单投诉信息", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayOrderComplaintInfoEntity playOrderComplaintInfo) {
        boolean success = playOrderComplaintInfoService.create(playOrderComplaintInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改订单投诉信息
     */
    //@PreAuthorize("@customSs.hasPermission('order:complaint:update')")
    @Log(title = "订单投诉信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayOrderComplaintInfoEntity playOrderComplaintInfo) {
        playOrderComplaintInfo.setId(id);
        boolean success = playOrderComplaintInfoService.update(playOrderComplaintInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除订单投诉信息
     */
    //@PreAuthorize("@customSs.hasPermission('order:complaint:delete')")
    @Log(title = "订单投诉信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playOrderComplaintInfoService.deletePlayOrderComplaintInfoByIds(ids));
    }
}
