package com.writeoff.module.system.controller;

import com.writeoff.common.api.ApiResponse;
import com.writeoff.common.api.PageResult;
import com.writeoff.module.system.model.PermissionInfo;
import com.writeoff.module.system.service.SystemUserService;
import com.writeoff.security.DataScopeType;
import com.writeoff.security.RequirePermission;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/permissions")
public class PermissionController {
    private final SystemUserService systemUserService;

    public PermissionController(SystemUserService systemUserService) {
        this.systemUserService = systemUserService;
    }

    @GetMapping
    @RequirePermission(value = "permission.read", dataScope = DataScopeType.TENANT, auditAction = "PERMISSION_LIST")
    public ApiResponse<PageResult<PermissionInfo>> list() {
        return ApiResponse.success(systemUserService.listPermissions());
    }
}
