<?php

namespace App\Http\Controllers\Admin;

use App\Enums\EventStatus;
use App\Enums\PaymentProofReviewStatus;
use App\Enums\PaymentStatus;
use App\Enums\PricingType;
use App\Enums\RegistrationStatus;
use App\Enums\UserStatus;
use App\Http\Controllers\Controller;
use App\Models\Event;
use App\Models\EventRegistration;
use App\Models\Game;
use App\Models\PlayerProfile;
use App\Models\PlayerRecord;
use App\Models\PlayerVideo;
use App\Models\User;
use Illuminate\View\View;

class DashboardController extends Controller
{
    public function index(): View
    {
        $metrics = [
            'total_users' => User::count(),
            'active_users' => User::where('status', UserStatus::Active)->count(),
            'completed_profiles' => PlayerProfile::where('profile_completion_percentage', '>=', 80)->count(),
            'supported_games' => Game::count(),
            'upcoming_events' => Event::where('starts_at', '>', now())
                ->whereNotIn('status', [EventStatus::Cancelled, EventStatus::Archived])
                ->count(),
            'open_registrations' => Event::where('status', EventStatus::RegistrationOpen)->count(),
            'pending_registrations' => EventRegistration::where('status', RegistrationStatus::Pending)->count(),
            'pending_payment_proofs' => EventRegistration::where('payment_status', PaymentStatus::ProofSubmitted)->count(),
            'confirmed_participants' => EventRegistration::where('status', RegistrationStatus::Confirmed)->count(),
            'free_events' => Event::where('pricing_type', PricingType::Free)->count(),
            'paid_events' => Event::where('pricing_type', PricingType::Paid)->count(),
            'recent_records' => PlayerRecord::where('created_at', '>=', now()->subDays(7))->count(),
            'recent_videos' => PlayerVideo::where('created_at', '>=', now()->subDays(7))->count(),
        ];

        return view('admin.dashboard.index', compact('metrics'));
    }
}
