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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.clerk.module.entity.PlayClerkCommodityEntity;
import com.starry.admin.modules.clerk.module.vo.PlayClerkCommodityQueryVo;
import com.starry.admin.modules.clerk.service.IPlayClerkCommodityService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import com.starry.common.utils.ConvertUtil;
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 java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 陪聊服务项目Controller
 *
 * @author admin
 * @since 2024-03-31
 */
@Api(tags = "陪聊服务项目", description = "陪聊服务项目管理相关接口，包括查询、新增、修改和删除等操作")
@RestController
@RequestMapping("/clerk/commodity")
public class PlayClerkCommodityController {
    @Resource
    private IPlayClerkCommodityService playClerkCommodityService;

    /**
     * 查询陪聊服务项目列表
     */
    @ApiOperation(value = "查询所有服务项目", notes = "获取所有陪聊服务项目列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayClerkCommodityQueryVo.class, responseContainer = "List")})
    @GetMapping("/listAllCommodity")
    public R listAllCommodity() {
        List<PlayClerkCommodityEntity> list = playClerkCommodityService.selectAll();
        return R.ok(ConvertUtil.entityToVoList(list, PlayClerkCommodityQueryVo.class));
    }

    /**
     * 查询陪聊服务项目列表
     */
    @ApiOperation(value = "分页查询服务项目", notes = "分页查询陪聊服务项目列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayClerkCommodityEntity.class, responseContainer = "Page")})
    @GetMapping("/list")
    public R list(@ApiParam(value = "查询条件") PlayClerkCommodityEntity playClerkCommodity) {
        IPage<PlayClerkCommodityEntity> list = playClerkCommodityService
                .selectPlayClerkCommodityByPage(playClerkCommodity);
        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 = PlayClerkCommodityEntity.class)})
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playClerkCommodityService.selectPlayClerkCommodityById(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 PlayClerkCommodityEntity playClerkCommodity) {
        boolean success = playClerkCommodityService.create(playClerkCommodity);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改陪聊服务项目
     */
    @ApiOperation(value = "修改服务项目", notes = "根据ID修改陪聊服务项目信息")
    @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 PlayClerkCommodityEntity playClerkCommodity) {
        playClerkCommodity.setId(id);
        boolean success = playClerkCommodityService.update(playClerkCommodity);
        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 = "操作成功", response = Integer.class)})
    @Log(title = "陪聊服务项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playClerkCommodityService.deletePlayClerkCommodityByIds(ids));
    }
}
