package com.zioinfo.kintex.common.audit;

import com.zioinfo.kintex.auth.KintexPrincipal;
import com.zioinfo.kintex.common.ApiResponse;
import com.zioinfo.kintex.common.PageResponse;
import com.zioinfo.kintex.system.SystemAccessGuard;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

/** 감사 로그 조회 API (/api/admin/audit). ADMIN 게이트. */
@RestController
@RequestMapping("/api/admin/audit")
public class AuditLogController {

    private final AuditLogService service;
    private final SystemAccessGuard guard;

    public AuditLogController(AuditLogService service, SystemAccessGuard guard) {
        this.service = service;
        this.guard = guard;
    }

    @GetMapping
    public ApiResponse<PageResponse<AuditLogDto>> list(
            @AuthenticationPrincipal KintexPrincipal principal,
            @RequestParam(required = false) String action,
            @RequestParam(required = false) String actorId,
            @RequestParam(required = false) String eventId,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "20") int size) {
        guard.requireAdmin(principal);
        return ApiResponse.ok(service.search(action, actorId, eventId, page, size));
    }
}
