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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.custom.module.entity.PlayCustomLeaveMsgEntity;
import com.starry.admin.modules.custom.module.vo.PlayCustomLeaveMsgQueryVo;
import com.starry.admin.modules.custom.module.vo.PlayCustomLeaveMsgReturnVo;
import com.starry.admin.modules.custom.service.IPlayCustomLeaveMsgService;
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("/custom/leave")
public class PlayCustomLeaveMsgController {
    @Resource
    private IPlayCustomLeaveMsgService playCustomLeaveMsgService;

    /**
     * 分页查询顾客留言列表
     */
    @PostMapping("/listByPage")
    public R list(@Validated @RequestBody PlayCustomLeaveMsgQueryVo vo) {
        IPage<PlayCustomLeaveMsgReturnVo> list = playCustomLeaveMsgService.selectByPage(vo);
        return R.ok(list);
    }

    /**
     * 获取顾客留言详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playCustomLeaveMsgService.selectPlayCustomLeaveMsgById(id));
    }

    /**
     * 新增顾客留言
     */
    //@PreAuthorize("@customSs.hasPermission('custom:leave:add')")
    @Log(title = "顾客留言", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayCustomLeaveMsgEntity playCustomLeaveMsg) {
        boolean success = playCustomLeaveMsgService.create(playCustomLeaveMsg);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改顾客留言
     */
    //@PreAuthorize("@customSs.hasPermission('custom:leave:update')")
    @Log(title = "顾客留言", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayCustomLeaveMsgEntity playCustomLeaveMsg) {
        playCustomLeaveMsg.setId(id);
        boolean success = playCustomLeaveMsgService.update(playCustomLeaveMsg);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除顾客留言
     */
    //@PreAuthorize("@customSs.hasPermission('custom:leave:delete')")
    @Log(title = "顾客留言", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playCustomLeaveMsgService.deletePlayCustomLeaveMsgByIds(ids));
    }
}
