<?php

namespace App\Http\Controllers\Meet\Concerns;

use App\Models\Room;
use App\Services\Integrations\EventsLinkService;
use App\Services\Meet\MeetPermissions;
use App\Support\EventsSourceLink;
use Illuminate\Http\Request;

trait ResolvesEventsLinkContext
{
    /** @return array{canManageEvents: bool, linkableEvents: list<array<string, mixed>>} */
    protected function eventsLinkContext(Request $request, Room $room): array
    {
        $canManageEvents = app(MeetPermissions::class)->can($this->member($request), 'meetings.manage');

        $linkableEvents = $canManageEvents && ! EventsSourceLink::isLinked($room)
            ? app(EventsLinkService::class)->linkableEvents($request->user())
            : [];

        return compact('canManageEvents', 'linkableEvents');
    }
}
