<?php

namespace App\Providers;

use App\Repositories\Contracts\AnnouncementRepositoryInterface;
use App\Repositories\Contracts\CategoryRepositoryInterface;
use App\Repositories\Contracts\CommentRepositoryInterface;
use App\Repositories\Contracts\CourseRepositoryInterface;
use App\Repositories\Contracts\FaqRepositoryInterface;
use App\Repositories\Contracts\GuideCardRepositoryInterface;
use App\Repositories\Contracts\HeroSlideRepositoryInterface;
use App\Repositories\Contracts\LeadRepositoryInterface;
use App\Repositories\Contracts\MenuRepositoryInterface;
use App\Repositories\Contracts\PageRepositoryInterface;
use App\Repositories\Contracts\ScheduleRepositoryInterface;
use App\Repositories\Contracts\SettingRepositoryInterface;
use App\Repositories\Contracts\UserRepositoryInterface;
use App\Repositories\Eloquent\AnnouncementRepository;
use App\Repositories\Eloquent\CategoryRepository;
use App\Repositories\Eloquent\CommentRepository;
use App\Repositories\Eloquent\CourseRepository;
use App\Repositories\Eloquent\FaqRepository;
use App\Repositories\Eloquent\GuideCardRepository;
use App\Repositories\Eloquent\HeroSlideRepository;
use App\Repositories\Eloquent\LeadRepository;
use App\Repositories\Eloquent\MenuRepository;
use App\Repositories\Eloquent\PageRepository;
use App\Repositories\Eloquent\ScheduleRepository;
use App\Repositories\Eloquent\SettingRepository;
use App\Repositories\Eloquent\UserRepository;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;

class AppServiceProvider extends ServiceProvider
{
    /**
     * @var array<class-string, class-string>
     */


    public array $bindings = [
        CategoryRepositoryInterface::class => CategoryRepository::class,
        CourseRepositoryInterface::class => CourseRepository::class,
        ScheduleRepositoryInterface::class => ScheduleRepository::class,
        AnnouncementRepositoryInterface::class => AnnouncementRepository::class,
        HeroSlideRepositoryInterface::class => HeroSlideRepository::class,
        LeadRepositoryInterface::class => LeadRepository::class,
        MenuRepositoryInterface::class => MenuRepository::class,
        CommentRepositoryInterface::class => CommentRepository::class,
        FaqRepositoryInterface::class => FaqRepository::class,
        GuideCardRepositoryInterface::class => GuideCardRepository::class,
        SettingRepositoryInterface::class => SettingRepository::class,
        PageRepositoryInterface::class => PageRepository::class,
        UserRepositoryInterface::class => UserRepository::class,
    ];

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

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        URL::forceScheme('https');

        Str::macro('turkishSlug', function (string $text, string $separator = '-'): string {
            $map = [
                'ç' => 'c',
                'ğ' => 'g',
                'ı' => 'i',
                'ö' => 'o',
                'ş' => 's',
                'ü' => 'u',
                'Ç' => 'c',
                'Ğ' => 'g',
                'İ' => 'i',
                'Ö' => 'o',
                'Ş' => 's',
                'Ü' => 'u',
            ];

            $text = strtr($text, $map);

            return Str::slug($text, $separator);
        });

        RateLimiter::for('leads', function (Request $request) {
            return Limit::perMinute(3)->by($request->ip());
        });

        RateLimiter::for('comments', function (Request $request) {
            return Limit::perMinute(3)->by($request->ip());
        });
    }
}
