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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.shop.module.entity.PlayClerkGiftInfoEntity;
import com.starry.admin.modules.shop.service.IPlayClerkGiftInfoService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 店员和礼物关系Controller
 *
 * @author admin
 * @since 2024-05-25
 */
@RestController
@RequestMapping("/play/clerkGift")
public class PlayClerkGiftInfoController {
    @Resource
    private IPlayClerkGiftInfoService playClerkGiftInfoService;

    /**
     * 查询店员和礼物关系列表
     */
    @GetMapping("/list")
    public R list(PlayClerkGiftInfoEntity playClerkGiftInfo) {
        IPage<PlayClerkGiftInfoEntity> list = playClerkGiftInfoService.selectPlayClerkGiftInfoByPage(playClerkGiftInfo);
        return R.ok(list);
    }

    /**
     * 获取店员和礼物关系详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playClerkGiftInfoService.selectPlayClerkGiftInfoById(id));
    }

    /**
     * 新增店员和礼物关系
     */
    @Log(title = "店员和礼物关系", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayClerkGiftInfoEntity playClerkGiftInfo) {
        boolean success = playClerkGiftInfoService.create(playClerkGiftInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改店员和礼物关系
     */
    @Log(title = "店员和礼物关系", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayClerkGiftInfoEntity playClerkGiftInfo) {
        playClerkGiftInfo.setId(id);
        boolean success = playClerkGiftInfoService.update(playClerkGiftInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除店员和礼物关系
     */
    @Log(title = "店员和礼物关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playClerkGiftInfoService.deletePlayClerkGiftInfoByIds(ids));
    }
}
