package com.tasteby.controller;

import com.tasteby.security.AuthUtil;
import com.tasteby.service.CacheService;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/admin")
public class AdminCacheController {

    private final CacheService cacheService;

    public AdminCacheController(CacheService cacheService) {
        this.cacheService = cacheService;
    }

    @PostMapping("/cache-flush")
    public Map<String, Object> flushCache() {
        AuthUtil.requireAdmin();
        cacheService.flush();
        return Map.of("ok", true);
    }

    /**
     * #336 — 캐시 상태 가시화: disabled / errorCount / lastError.
     * 외부 모니터링 도구 도입 전 운영자가 어드민에서 확인 가능.
     */
    @GetMapping("/cache/stats")
    public CacheService.CacheStats cacheStats() {
        AuthUtil.requireAdmin();
        return cacheService.getStats();
    }
}
