<?php

namespace App\Http\Controllers;

use App\Domain\Event\Models\Event;
use App\Domain\Website\Services\WebsiteSectionService;

class PublicEventController extends Controller
{
    public function index(string $slug, WebsiteSectionService $sectionService)
    {
        $academy = app('current_academy');
        $settings = app('website_settings');
        $sections = $sectionService->getEnabled($academy);

        $events = Event::withoutGlobalScopes()
            ->where('academy_id', $academy->id)
            ->whereNotIn('status', ['draft', 'cancelled'])
            ->with('cover')
            ->orderByDesc('starts_at')
            ->paginate(12);

        return view('website.events.index', compact('academy', 'events', 'settings', 'sections'));
    }

    public function show(string $slug, string $eventSlug, WebsiteSectionService $sectionService)
    {
        $academy = app('current_academy');
        $settings = app('website_settings');
        $sections = $sectionService->getEnabled($academy);

        $event = Event::withoutGlobalScopes()
            ->where('academy_id', $academy->id)
            ->where('slug', $eventSlug)
            ->where('status', '!=', 'draft')
            ->with(['cover', 'gallery', 'facility'])
            ->firstOrFail();

        return view('website.events.show', compact('academy', 'event', 'settings', 'sections'));
    }
}
