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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.custom.module.entity.PlayCustomGiftInfoEntity;
import com.starry.admin.modules.custom.service.IPlayCustomGiftInfoService;
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-06-05
 */
@RestController
@RequestMapping("/custom/giff")
public class PlayCustomGiftInfoController {
    @Resource
    private IPlayCustomGiftInfoService playCustomGiftInfoService;

    /**
     * 查询顾客和礼物关系列表
     */
    @GetMapping("/list")
    public R list(PlayCustomGiftInfoEntity playCustomGiftInfo) {
        IPage<PlayCustomGiftInfoEntity> list = playCustomGiftInfoService.selectPlayCustomGiftInfoByPage(playCustomGiftInfo);
        return R.ok(list);
    }

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

    /**
     * 新增顾客和礼物关系
     */
    @Log(title = "顾客和礼物关系", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayCustomGiftInfoEntity playCustomGiftInfo) {
        boolean success = playCustomGiftInfoService.create(playCustomGiftInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

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

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