<?php

namespace Database\Seeders;

use App\Models\RateLimitSetting;
use Illuminate\Database\Seeder;

class RateLimitSeeder extends Seeder
{
    public function run(): void
    {
        $settings = [
            [
                'endpoint' => null,
                'max_attempts' => 100,
                'decay_seconds' => 60,
                'is_enabled' => true,
                'description' => 'Global varsayılan ayar',
            ],
            [
                'endpoint' => 'POST /api/auth/login',
                'max_attempts' => 5,
                'decay_seconds' => 60,
                'is_enabled' => true,
                'description' => 'Giriş denemesi limiti',
            ],
            [
                'endpoint' => 'POST /api/auth/register',
                'max_attempts' => 3,
                'decay_seconds' => 60,
                'is_enabled' => true,
                'description' => 'Kayıt denemesi limiti',
            ],
            [
                'endpoint' => 'POST /api/auth/forgot-password',
                'max_attempts' => 3,
                'decay_seconds' => 120,
                'is_enabled' => true,
                'description' => 'Şifre sıfırlama limiti',
            ],
            [
                'endpoint' => 'POST /api/auth/forgot-password-sms',
                'max_attempts' => 3,
                'decay_seconds' => 120,
                'is_enabled' => true,
                'description' => 'SMS şifre sıfırlama limiti',
            ],
            [
                'endpoint' => 'POST /api/auth/phone/send-code',
                'max_attempts' => 3,
                'decay_seconds' => 120,
                'is_enabled' => true,
                'description' => 'Telefon doğrulama kodu gönderme limiti',
            ],
        ];

        foreach ($settings as $setting) {
            RateLimitSetting::updateOrCreate(
                ['endpoint' => $setting['endpoint']],
                $setting
            );
        }

        RateLimitSetting::clearCache();
    }
}
