<?php
declare(strict_types=1);

namespace App\Service;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

class EventService
{
    private const EVENT_DATA = [
        'title' => 'Abiball 2025',
        'description' => 'Der Abiball der Freien Waldorfschule Bremen Osterholz und Touler Straße',
        'location' => 'Graubündener Str. 4, 28325 Bremen',
        'start' => '20250628T173000',
        'end' => '20250629T030000',
    ];

    public function generateIcs(): Response
    {
        $data = [
            'BEGIN:VCALENDAR',
            'VERSION:2.0',
            'BEGIN:VEVENT',
            'DTSTART:' . self::EVENT_DATA['start'],
            'DTEND:' . self::EVENT_DATA['end'],
            'SUMMARY:' . self::EVENT_DATA['title'],
            'DESCRIPTION:' . self::EVENT_DATA['description'],
            'LOCATION:' . self::EVENT_DATA['location'],
            'END:VEVENT',
            'END:VCALENDAR'
        ];

        return new Response(implode("\r\n", $data), headers: [
            'Content-Type' => 'text/calendar; charset=utf-8',
            'Content-Disposition' => 'attachment; filename="event.ics"'
        ]);
    }

    public function generateGoogleRedirect(): Response
    {
        return new RedirectResponse('https://calendar.google.com/calendar/render?' . http_build_query([
                'action' => 'TEMPLATE',
                'text' => self::EVENT_DATA['title'],
                'dates' => self::EVENT_DATA['start'] . '/' . self::EVENT_DATA['end'],
                'details' => self::EVENT_DATA['description'],
                'location' => self::EVENT_DATA['location'],
            ]));
    }
}