package com.zioinfo.kintex.system.loginhistory;

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 게이트. 읽기 전용. */
@RestController
@RequestMapping("/api/admin/login-history")
public class LoginHistoryController {

    private final LoginHistoryService service;
    private final SystemAccessGuard guard;

    public LoginHistoryController(LoginHistoryService service, SystemAccessGuard guard) {
        this.service = service;
        this.guard = guard;
    }

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