<?php

namespace App\Filament\Resources\TenantResource\Pages;

use App\Filament\Resources\TenantResource;
use App\Models\User;
use App\Support\TenantRole;
use Filament\Resources\Pages\CreateRecord;

class CreateTenant extends CreateRecord
{
    protected static string $resource = TenantResource::class;

    protected function afterCreate(): void
    {
        $user = auth()->user();

        if (! $user instanceof User) {
            return;
        }

        $user->tenants()->syncWithoutDetaching([
            $this->record->getKey() => ['role' => TenantRole::Owner->value],
        ]);
    }
}
