package com.writeoff.module.system.controller;

import com.writeoff.common.api.ApiResponse;
import com.writeoff.common.api.PageResult;
import com.writeoff.module.system.model.OperationAuditLogInfo;
import com.writeoff.module.system.service.OperationAuditLogService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/platform/audit-logs")
public class PlatformAuditLogController {
    private final OperationAuditLogService operationAuditLogService;

    public PlatformAuditLogController(OperationAuditLogService operationAuditLogService) {
        this.operationAuditLogService = operationAuditLogService;
    }

    @GetMapping
    @RequirePermission(value = "platform.audit.read", domain = PermissionDomain.PLATFORM, dataScope = DataScopeType.GLOBAL_READONLY, auditAction = "PLATFORM_AUDIT_LOG_LIST")
    public ApiResponse<PageResult<OperationAuditLogInfo>> list(
            @RequestParam(value = "userId", required = false) Long userId,
            @RequestParam(value = "actionCode", required = false) String actionCode,
            @RequestParam(value = "tenantId", required = false) Long tenantId,
            @RequestParam(value = "scope", required = false) String scope,
            @RequestParam(value = "pageNo", required = false) Integer pageNo,
            @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        return ApiResponse.success(operationAuditLogService.listPlatform(userId, actionCode, tenantId, scope, pageNo, pageSize));
    }
}
