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

import com.starry.admin.modules.clerk.module.entity.PlayClerkTypeInfoEntity;
import com.starry.admin.modules.clerk.module.vo.PlayClerkTypeInfoAddVo;
import com.starry.admin.modules.clerk.module.vo.PlayClerkTypeInfoQueryVo;
import com.starry.admin.modules.clerk.service.IPlayClerkTypeInfoService;
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-05-31
 */
@Api(tags = "店员分类管理", description = "店员分类信息管理相关接口，包括查询、新增、修改和删除等操作")
@RestController
@RequestMapping("/clerk/type")
public class PlayClerkTypeInfoController {
    @Resource
    private IPlayClerkTypeInfoService playClerkTypeInfoService;

    /**
     * 查询店员分类信息列表
     */
    @ApiOperation(value = "查询所有分类", notes = "获取所有店员分类信息列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayClerkTypeInfoEntity.class, responseContainer = "List")})
    @GetMapping("/listByAll")
    public R listByAll() {
        return R.ok(playClerkTypeInfoService.selectByAll());
    }

    @ApiOperation(value = "分页查询分类", notes = "分页查询店员分类信息列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayClerkTypeInfoEntity.class, responseContainer = "Page")})
    @PostMapping("/listByPage")
    public R listByPage(
            @ApiParam(value = "查询条件", required = true) @Validated @RequestBody PlayClerkTypeInfoQueryVo vo) {
        return R.ok(playClerkTypeInfoService.selectByPage(vo));
    }

    /**
     *
     * /** 新增店员分类信息
     */
    @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) @Validated @RequestBody PlayClerkTypeInfoAddVo vo) {
        boolean success = playClerkTypeInfoService.create(ConvertUtil.entityToVo(vo, PlayClerkTypeInfoEntity.class));
        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 PlayClerkTypeInfoEntity playClerkTypeInfo) {
        playClerkTypeInfo.setId(id);
        boolean success = playClerkTypeInfoService.update(playClerkTypeInfo);
        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(playClerkTypeInfoService.deletePlayClerkTypeInfoByIds(ids));
    }
}
