package com.zioinfo.kintex.system.errorlog;

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. ADMIN 게이트. 읽기 전용(요약 1줄). */
@RestController
@RequestMapping("/api/admin/error-log")
public class ErrorLogController {

    private final ErrorLogService service;
    private final SystemAccessGuard guard;

    public ErrorLogController(ErrorLogService service, SystemAccessGuard guard) {
        this.service = service;
        this.guard = guard;
    }

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