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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 店员和礼物关系Controller
 *
 * @author admin
 * @since 2024-05-25
 */
@Api(tags = "店员礼物关联管理", description = "店员和礼物关系管理相关接口，包括查询、新增、修改和删除等操作")
@RestController
@RequestMapping("/play/clerkGift")
public class PlayClerkGiftInfoController {
    @Resource
    private IPlayClerkGiftInfoService playClerkGiftInfoService;

    /**
     * 查询店员和礼物关系列表
     */
    @ApiOperation(value = "查询店员礼物关联列表", notes = "分页查询店员和礼物关系列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayClerkGiftInfoEntity.class, responseContainer = "Page")})
    @GetMapping("/list")
    public R list(@ApiParam(value = "查询条件") PlayClerkGiftInfoEntity playClerkGiftInfo) {
        IPage<PlayClerkGiftInfoEntity> list = playClerkGiftInfoService.selectPlayClerkGiftInfoByPage(playClerkGiftInfo);
        return R.ok(list);
    }

    /**
     * 获取店员和礼物关系详细信息
     */
    @ApiOperation(value = "获取关联详情", notes = "根据ID获取店员和礼物关系详细信息")
    @ApiImplicitParam(name = "id", value = "关联ID", required = true, paramType = "path", dataType = "String", example = "1")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功", response = PlayClerkGiftInfoEntity.class)})
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playClerkGiftInfoService.selectPlayClerkGiftInfoById(id));
    }

    /**
     * 新增店员和礼物关系
     */
    @ApiOperation(value = "新增关联信息", notes = "新增店员和礼物关系信息")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "添加失败，包含详细错误信息")})
    @Log(title = "店员和礼物关系", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@ApiParam(value = "关联信息", required = true) @RequestBody PlayClerkGiftInfoEntity playClerkGiftInfo) {
        boolean success = playClerkGiftInfoService.create(playClerkGiftInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改店员和礼物关系
     */
    @ApiOperation(value = "修改关联信息", notes = "修改店员和礼物关系信息")
    @ApiImplicitParam(name = "id", value = "关联ID", required = true, paramType = "path", dataType = "String", example = "1")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "修改失败，包含详细错误信息")})
    @Log(title = "店员和礼物关系", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id,
            @ApiParam(value = "关联信息", required = true) @RequestBody PlayClerkGiftInfoEntity playClerkGiftInfo) {
        playClerkGiftInfo.setId(id);
        boolean success = playClerkGiftInfoService.update(playClerkGiftInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除店员和礼物关系
     */
    @ApiOperation(value = "删除关联信息", notes = "根据ID批量删除店员和礼物关系信息")
    @ApiImplicitParam(name = "ids", value = "关联ID数组", required = true, paramType = "path", dataType = "String[]", example = "1,2,3")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @Log(title = "店员和礼物关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playClerkGiftInfoService.deletePlayClerkGiftInfoByIds(ids));
    }
}
