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 org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 店员分类信息Controller
 *
 * @author admin
 * @since 2024-05-31
 */
@RestController
@RequestMapping("/clerk/type")
public class PlayClerkTypeInfoController {
    @Resource
    private IPlayClerkTypeInfoService playClerkTypeInfoService;

    /**
     * 查询店员分类信息列表
     */
    @GetMapping("/listByAll")
    public R listByAll() {
        return R.ok(playClerkTypeInfoService.selectByAll());
    }

    @PostMapping("/listByPage")
    public R listByPage(@Validated @RequestBody PlayClerkTypeInfoQueryVo vo) {
        return R.ok(playClerkTypeInfoService.selectByPage(vo));
    }


    /**

    /**
     * 新增店员分类信息
     */
    @Log(title = "店员分类信息", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@Validated @RequestBody PlayClerkTypeInfoAddVo vo) {
        boolean success = playClerkTypeInfoService.create(ConvertUtil.entityToVo(vo, PlayClerkTypeInfoEntity.class));
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改店员分类信息
     */
    @Log(title = "店员分类信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayClerkTypeInfoEntity playClerkTypeInfo) {
        playClerkTypeInfo.setId(id);
        boolean success = playClerkTypeInfoService.update(playClerkTypeInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除店员分类信息
     */
    @Log(title = "店员分类信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playClerkTypeInfoService.deletePlayClerkTypeInfoByIds(ids));
    }
}
