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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.custom.entity.PlayCustomFollowInfoEntity;
import com.starry.admin.modules.custom.service.IPlayCustomFollowInfoService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 顾客关注陪聊信息Controller
 *
 * @author admin
 * @since 2024-04-30
 */
@RestController
@RequestMapping("/play/follow")
public class PlayCustomFollowInfoController {
    @Resource
    private IPlayCustomFollowInfoService playCustomFollowInfoService;

    /**
     * 查询顾客关注陪聊信息列表
     */
    @PreAuthorize("@customSs.hasPermission('play:info:list')")
    @GetMapping("/list")
    public R list(PlayCustomFollowInfoEntity playCustomFollowInfo) {
        IPage<PlayCustomFollowInfoEntity> list = playCustomFollowInfoService.selectPlayCustomFollowInfoByPage(playCustomFollowInfo);
        return R.ok(list);
    }

    /**
     * 获取顾客关注陪聊信息详细信息
     */
    @PreAuthorize("@customSs.hasPermission('play:info:query')")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playCustomFollowInfoService.selectPlayCustomFollowInfoById(id));
    }

    /**
     * 新增顾客关注陪聊信息
     */
    @PreAuthorize("@customSs.hasPermission('play:info:create')")
    @Log(title = "顾客关注陪聊信息", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayCustomFollowInfoEntity playCustomFollowInfo) {
        boolean success = playCustomFollowInfoService.create(playCustomFollowInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改顾客关注陪聊信息
     */
    @PreAuthorize("@customSs.hasPermission('play:info:edit')")
    @Log(title = "顾客关注陪聊信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayCustomFollowInfoEntity playCustomFollowInfo) {
        playCustomFollowInfo.setId(id);
        boolean success = playCustomFollowInfoService.update(playCustomFollowInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除顾客关注陪聊信息
     */
    @PreAuthorize("@customSs.hasPermission('play:info:remove')")
    @Log(title = "顾客关注陪聊信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playCustomFollowInfoService.deletePlayCustomFollowInfoByIds(ids));
    }
}
