package com.zanxiang.game.module.manage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.module.manage.pojo.params.RoleAssignRecordAddParam;
import com.zanxiang.game.module.manage.pojo.params.RoleAssignRecordListParam;
import com.zanxiang.game.module.manage.pojo.params.RoleSysUserAssignParam;
import com.zanxiang.game.module.manage.pojo.vo.RoleAssignRecordListVO;
import com.zanxiang.game.module.manage.service.IRoleAssignRecordService;
import com.zanxiang.module.util.pojo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role/assign/record")
@Slf4j
public class RoleAssignController {

    @Autowired
    private IRoleAssignRecordService roleAssignRecordService;

    @GetMapping(value = "/update/status/sync")
    @PreAuthorize(permissionKey = "manage:roleAssign:updateStatusSync")
    public ResultVO<Void> updateStatusSync() {
        roleAssignRecordService.updateStatusSync();
        return ResultVO.ok();
    }

    @PostMapping(value = "/config/sysUser")
    @PreAuthorize(permissionKey = "manage:roleAssign:configSysUser")
    public ResultVO<Boolean> configSysUser(@Validated @RequestBody RoleSysUserAssignParam param) {
        return ResultVO.ok(roleAssignRecordService.configSysUser(param));
    }

    @PostMapping(value = "/modify")
    @PreAuthorize(permissionKey = "manage:roleAssign:modify")
    public ResultVO<Boolean> modify(@Validated @RequestBody RoleAssignRecordAddParam param) {
        return ResultVO.ok(roleAssignRecordService.modify(param));
    }

    @PostMapping(value = "/list")
    @PreAuthorize(permissionKey = "manage:roleAssign:list")
    public ResultVO<IPage<RoleAssignRecordListVO>> list(@Validated @RequestBody RoleAssignRecordListParam param) {
        return ResultVO.ok(roleAssignRecordService.listOfPage(param));
    }

    @DeleteMapping(value = "/delete/{id}")
    @PreAuthorize(permissionKey = "manage:roleAssign:delete")
    public ResultVO<Boolean> deleteById(@PathVariable Long id) {
        return ResultVO.ok(roleAssignRecordService.deleteById(id));
    }
}
