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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.gift.module.entity.PlayGiftInfoEntity;
import com.starry.admin.modules.gift.service.IPlayGiftInfoService;
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-04-25
 */
@RestController
@RequestMapping("/play/giff")
public class PlayGiftInfoController {
    @Resource
    private IPlayGiftInfoService playGiftInfoService;

    /**
     * 查询礼物列表
     */
    @GetMapping("/list")
    public R list(PlayGiftInfoEntity playGiftInfo) {
        IPage<PlayGiftInfoEntity> list = playGiftInfoService.selectPlayGiftInfoByPage(playGiftInfo);
        return R.ok(list);
    }

    /**
     * 获取礼物详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playGiftInfoService.selectPlayGiftInfoById(id));
    }

    /**
     * 新增礼物
     */
    @Log(title = "礼物", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayGiftInfoEntity playGiftInfo) {
        boolean success = playGiftInfoService.create(playGiftInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改礼物
     */
    @Log(title = "礼物", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayGiftInfoEntity playGiftInfo) {
        playGiftInfo.setId(id);
        boolean success = playGiftInfoService.update(playGiftInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除礼物
     */
    @Log(title = "礼物", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playGiftInfoService.deletePlayGiftInfoByIds(ids));
    }
}
