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

import javax.annotation.Resource;

/**
 * 顾客Controller
 *
 * @author admin
 * @since 2024-04-08
 */
@RestController
@RequestMapping("/custom/user")
public class PlayCustomUserInfoController {
    @Resource
    private IPlayCustomUserInfoService playCustomUserInfoService;

    /**
     * 查询顾客列表
     */
    @PostMapping("/listByPage")
    public R list(@Validated @RequestBody PlayCustomUserQueryVo vo) {
        IPage<PlayCustomUserReturnVo> list = playCustomUserInfoService.selectByPage(vo);
        return R.ok(list);
    }

    /**
     * 获取顾客详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playCustomUserInfoService.selectById(id));
    }

    /**
     * 新增顾客
     */
    @Log(title = "顾客", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayCustomUserInfoEntity playCustomUserInfo) {
        boolean success = playCustomUserInfoService.create(playCustomUserInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改顾客状态
     */
    @Log(title = "顾客", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateState")
    public R updateState(@Validated @RequestBody PlayCustomUserStateEditVo vo) {
        PlayCustomUserInfoEntity entity = ConvertUtil.entityToVo(vo, PlayCustomUserInfoEntity.class);
        boolean success = playCustomUserInfoService.update(entity);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 修改顾客
     */
    @Log(title = "顾客", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayCustomUserInfoEntity playCustomUserInfo) {
        playCustomUserInfo.setId(id);
        boolean success = playCustomUserInfoService.update(playCustomUserInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除顾客
     */
    @Log(title = "顾客", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playCustomUserInfoService.deletePlayCustomUserInfoByIds(ids));
    }
}
