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.PlatformIamService;
import com.writeoff.security.DataScopeType;
import com.writeoff.security.PermissionDomain;
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/platform/permissions")
public class PlatformPermissionController {
    private final PlatformIamService platformIamService;

    public PlatformPermissionController(PlatformIamService platformIamService) {
        this.platformIamService = platformIamService;
    }

    @GetMapping
    @RequirePermission(value = "platform.permission.read", domain = PermissionDomain.PLATFORM, dataScope = DataScopeType.GLOBAL_READONLY, auditAction = "PLATFORM_PERMISSION_LIST")
    public ApiResponse<PageResult<PermissionInfo>> list() {
        return ApiResponse.success(platformIamService.listPermissions());
    }
}
