<?php

/*
 * This file is part of the official PHP MCP SDK.
 *
 * A collaboration between Symfony and the PHP Foundation.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace plugins\AiAssistant\Mcp\Examples\ComplexToolSchema;

use Mcp\Capability\Attribute\McpTool;
use plugins\AiAssistant\Mcp\Examples\ComplexToolSchema\Model\Attendee;
use plugins\AiAssistant\Mcp\Examples\ComplexToolSchema\Model\EventPriority;
use plugins\AiAssistant\Mcp\Examples\ComplexToolSchema\Model\EventType;

final class McpEventScheduler
{
    // TODO logs should work
//    public function __construct(
//        private readonly LoggerInterface $logger,
//    ) {
//    }

    /**
     * Schedules a new event.
     * The inputSchema for this tool will reflect all parameter types and defaults.
     *
     * @param string        $title       the title of the event
     * @param string        $date        the date of the event (YYYY-MM-DD)
     * @param EventType     $type        the type of event
     * @param string|null   $time        the time of the event (HH:MM), optional
     * @param EventPriority $priority    The priority of the event. Defaults to Normal.
     * @param Attendee[]|null $attendees an optional list of attendees with name and email
     * @param bool          $sendInvites send calendar invites to attendees? Defaults to true if attendees are provided
     *
     * @return array<string, mixed> confirmation of the scheduled event
     */
    #[McpTool(name: 'schedule_event')]
    public function scheduleEvent(
        string $title,
        string $date,
        EventType $type,
        ?string $time = null,
        EventPriority $priority = EventPriority::Normal,
        ?array $attendees = null,
        bool $sendInvites = true,
    ): array {
        // TODO logs should work
        //$this->logger->info("Tool 'schedule_event' called", compact('title', 'date', 'type', 'time', 'priority', 'attendees', 'sendInvites'));

        // Simulate scheduling logic
        $eventDetails = [
            'title' => $title,
            'date' => $date,
            'type' => $type->value, // Use enum value
            'time' => $time ?? 'All day',
            'priority' => $priority->name, // Use enum name
            'attendees' => $attendees ?? [],
//            'attendees' => array_map(
//                fn(Attendee $a) => ['name' => $a->name, 'email' => $a->email],
//                $attendees ?? []
//            ),
            'invites_will_be_sent' => ($attendees && $sendInvites),
            'event_url' => 'http://php85.devel.tina.dcs/dan.baluta/tina3/project/disp.php?module=Home',
        ];

        // In a real app, this would interact with a calendar service
        // TODO logs should work
        //$this->logger->info('Event scheduled', ['details' => $eventDetails]);

        return [
            'success' => true,
            'message' => \sprintf('Event "%s" scheduled successfully for "%s".', $title, $date),
            'event_details' => $eventDetails,
        ];
    }
}
