<?php

namespace App\Providers;

use App\Tenancy\TenantManager;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->singleton(TenantManager::class);
    }

    public function boot(): void
    {
        // Behind a TLS-terminating proxy (Cloudflare → Coolify Traefik → Octane).
        // Force https on URL generation, but DON'T force root URL — each tenant
        // subdomain must keep its own host so Livewire/CSRF work per-tenant.
        if (! $this->app->runningInConsole() && (str_starts_with(config('app.url'), 'https://') || env('FORCE_HTTPS'))) {
            URL::forceScheme('https');
        }
    }
}
