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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.custom.module.entity.PlayCustomUserInfoEntity;
import com.starry.admin.modules.custom.module.vo.PlayCustomUserQueryVo;
import com.starry.admin.modules.custom.module.vo.PlayCustomUserReturnVo;
import com.starry.admin.modules.custom.module.vo.PlayCustomUserStateEditVo;
import com.starry.admin.modules.custom.service.IPlayCustomUserInfoService;
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 javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 顾客Controller
 *
 * @author admin
 * @since 2024-04-08
 */
@Api(tags = "顾客管理", description = "顾客信息管理相关接口，包括查询、新增、修改和删除等操作")
@RestController
@RequestMapping("/custom/user")
public class PlayCustomUserInfoController {
    @Resource
    private IPlayCustomUserInfoService playCustomUserInfoService;

    /**
     * 查询顾客列表
     */
    @ApiOperation(value = "分页查询顾客列表", notes = "分页查询顾客信息列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayCustomUserReturnVo.class, responseContainer = "Page")})
    @PostMapping("/listByPage")
    public R list(@ApiParam(value = "查询条件", required = true) @Validated @RequestBody PlayCustomUserQueryVo vo) {
        IPage<PlayCustomUserReturnVo> list = playCustomUserInfoService.selectByPage(vo);
        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 = PlayCustomUserInfoEntity.class)})
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playCustomUserInfoService.selectById(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 PlayCustomUserInfoEntity playCustomUserInfo) {
        boolean success = playCustomUserInfoService.create(playCustomUserInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改顾客状态
     */
    @ApiOperation(value = "修改顾客状态", notes = "修改顾客的状态信息，如黑名单状态、关注状态等")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "修改失败")})
    @Log(title = "顾客", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateState")
    public R updateState(
            @ApiParam(value = "顾客状态信息", required = true) @Validated @RequestBody PlayCustomUserStateEditVo vo) {
        PlayCustomUserInfoEntity entity = ConvertUtil.entityToVo(vo, PlayCustomUserInfoEntity.class);
        boolean success = playCustomUserInfoService.update(entity);
        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 PlayCustomUserInfoEntity playCustomUserInfo) {
        playCustomUserInfo.setId(id);
        boolean success = playCustomUserInfoService.update(playCustomUserInfo);
        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(playCustomUserInfoService.deletePlayCustomUserInfoByIds(ids));
    }
}
