<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\V1\Stat\StatAlertRequest;
use App\Http\Requests\V1\Stat\StatDailyRequest;
use App\Http\Requests\V1\Stat\StatMonthlyRequest;
use App\Services\Stats\StatQueryService;
use Illuminate\Http\JsonResponse;

class StatController extends Controller
{
    public function __construct(
        private readonly StatQueryService $statQueryService
    ) {}

    /**
     * 대시보드 요약 통계 (sam_stat 기반)
     */
    public function summary(): JsonResponse
    {
        $data = $this->statQueryService->getDashboardSummary();

        return ApiResponse::handle(['data' => $data], __('message.fetched'));
    }

    /**
     * 일간 통계 조회
     */
    public function daily(StatDailyRequest $request): JsonResponse
    {
        $data = $this->statQueryService->getDailyStat(
            $request->validated('domain'),
            $request->validated()
        );

        return ApiResponse::handle(['data' => $data], __('message.fetched'));
    }

    /**
     * 월간 통계 조회
     */
    public function monthly(StatMonthlyRequest $request): JsonResponse
    {
        $data = $this->statQueryService->getMonthlyStat(
            $request->validated('domain'),
            $request->validated()
        );

        return ApiResponse::handle(['data' => $data], __('message.fetched'));
    }

    /**
     * 알림 목록 조회
     */
    public function alerts(StatAlertRequest $request): JsonResponse
    {
        $data = $this->statQueryService->getAlerts($request->validated());

        return ApiResponse::handle(['data' => $data], __('message.fetched'));
    }
}
