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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.clerk.module.entity.PlayClerkClassificationInfoEntity;
import com.starry.admin.modules.clerk.service.IPlayClerkClassificationInfoService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 店员分类Controller
 *
 * @author admin
 * @since 2024-04-06
 */
@RestController
@RequestMapping("/clerk/class")
public class PlayClerkClassificationInfoController {
    @Resource
    private IPlayClerkClassificationInfoService playClerkClassificationInfoService;

    /**
     * 查询店员分类列表
     */
    @GetMapping("/listAll")
    public R listAll() {
        List<PlayClerkClassificationInfoEntity> list = playClerkClassificationInfoService.selectAll();
        return R.ok(list);
    }


    /**
     * 查询店员分类列表
     */
    @GetMapping("/list")
    public R list(PlayClerkClassificationInfoEntity playClerkClassificationInfo) {
        IPage<PlayClerkClassificationInfoEntity> list = playClerkClassificationInfoService.selectPlayClerkClassificationInfoByPage(playClerkClassificationInfo);
        return R.ok(list);
    }

    /**
     * 获取店员分类详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playClerkClassificationInfoService.selectPlayClerkClassificationInfoById(id));
    }

    /**
     * 新增店员分类
     */
    @Log(title = "店员分类", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayClerkClassificationInfoEntity playClerkClassificationInfo) {
        boolean success = playClerkClassificationInfoService.create(playClerkClassificationInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

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

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