<?php

namespace App\Providers;

use App\Helpers\UrlHelper;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        // Bind Telegram Bot API
        $this->app->bind(\Telegram\Bot\Api::class, function ($app) {
            return new \Telegram\Bot\Api();
        });
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        ResetPassword::createUrlUsing(function (object $notifiable, string $token) {
            return config('app.frontend_url')."/password-reset/$token?email={$notifiable->getEmailForPasswordReset()}";
        });

        if (!app()->runningInConsole()) {
            $publicBase = UrlHelper::getPublicBaseUrl();
            if ($publicBase !== '') {
                URL::forceRootUrl($publicBase);
            }
        }
    }
}
