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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.play.module.entity.PlayUserInfoEntity;
import com.starry.admin.modules.play.module.vo.PlayUserInfoAddVo;
import com.starry.admin.modules.play.module.vo.PlayUserInfoQueryVo;
import com.starry.admin.modules.play.module.vo.PlayUserInfoUpEditVo;
import com.starry.admin.modules.play.service.IPlayUserInfoService;
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-03-30
 */
@RestController
@RequestMapping("/play/user")
public class PlayUserInfoController {
    @Resource
    private IPlayUserInfoService playUserInfoService;

    /**
     * 查询账号列表
     */
    //@PreAuthorize("@customSs.hasPermission('play:user:list')")
    @PostMapping("/listByPage")
    public R listAll(@Validated @RequestBody PlayUserInfoQueryVo vo) {
        IPage<PlayUserInfoEntity> list = playUserInfoService.selectPlayUserInfoByPage(vo);
        return R.ok(list);
    }

    /**
     * 获取账号详细信息
     */
    //@PreAuthorize("@customSs.hasPermission('play:user:list')")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playUserInfoService.selectPlayUserInfoById(id));
    }

    /**
     * 新增账号
     */
    //@PreAuthorize("@customSs.hasPermission('play:user:add')")
    @Log(title = "账号", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@Validated @RequestBody PlayUserInfoAddVo vo) {
        PlayUserInfoEntity entity = ConvertUtil.entityToVo(vo, PlayUserInfoEntity.class);
        boolean success = playUserInfoService.create(entity);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改账号
     */
    //@PreAuthorize("@customSs.hasPermission('play:user:update')")
    @Log(title = "账号", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update")
    public R update(@Validated @RequestBody PlayUserInfoUpEditVo vo) {
        PlayUserInfoEntity entity = ConvertUtil.entityToVo(vo, PlayUserInfoEntity.class);
        boolean success = playUserInfoService.update(entity);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除账号
     */
    //@PreAuthorize("@customSs.hasPermission('play:user:delete')")
    @Log(title = "账号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playUserInfoService.deletePlayUserInfoByIds(ids));
    }
}
