<?php

namespace App\Http\Controllers;

use App\Domain\Event\Models\Event;

class PublicEventController extends Controller
{
    public function index(string $slug)
    {
        $academy = app('current_academy');

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

        $settings = app('website_settings');

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

    public function show(string $slug, string $eventSlug)
    {
        $academy = app('current_academy');

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

        $settings = app('website_settings');

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