private function prepareResult(array $events, Production $production = null): array
    {
        // Create array of events for calendar.
        $result = [
            'success' => 1,
            'result' => [],
        ];

        // Index schedules so we don't duplicate them.
        $schedules = [];
        foreach ($events as $event) {
            $event_production = (null !== $production) ? $production : $event->getGroups()[0];
            if (null === $schedule = $event->getSchedule()) {
                // Add the event directly.
                $result['result'][] = [
                    'icon' => 'calendar',
                    'id' => 'event:' . $event->getId(),
                    'title' => ((null === $production) ? $event_production->getName() . ': ' : '') . $event->getName(),
                    'url' => $this->url_generator->generate(
                        'bkstg_event_read',
                        ['production_slug' => $event_production->getSlug(), 'id' => $event->getId()]
                    ),
                    'class' => 'event-' . $event->getColour(),
                    'start' => $event->getStart()->format('U') * 1000,
                    'end' => $event->getEnd()->format('U') * 1000,
                ];
            } elseif (!isset($schedules[$schedule->getId()])) {
                // Add the schedule instead of the event.
                $schedules[$schedule->getId()] = true;
                $result['result'][] = [
                    'icon' => 'list',
                    'id' => 'schedule:' . $schedule->getId(),
                    'title' => (
                        (null === $production) ? $event_production->getName() . ': ' : ''
                    ) . $schedule->getName(),
                    'url' => $this->url_generator->generate(
                        'bkstg_schedule_read',
                        ['production_slug' => $event_production->getSlug(), 'id' => $schedule->getId()]
                    ),
                    'class' => 'event-' . $schedule->getColour(),
                    'start' => $schedule->getStart()->format('U') * 1000,
                    'end' => $schedule->getEnd()->format('U') * 1000,
                ];
            }
        }

        return $result;
    }