<?php

namespace App\Providers;

use App\Models\Partnership;
use App\Models\Profile;
use App\Models\User;
use App\Models\Workspace;
use App\Observers\PartnershipObserver;
use App\Policies\PartnershipPolicy;
use App\Policies\WorkspacePolicy;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Partnership::observe(PartnershipObserver::class);

        Gate::policy(Partnership::class, PartnershipPolicy::class);
        Gate::policy(Workspace::class, WorkspacePolicy::class);

        User::created(function (User $user): void {
            Profile::query()->firstOrCreate(
                ['user_id' => $user->id],
                ['display_name' => $user->name]
            );
        });
    }
}
