<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

class SystemSettingsSeeder extends Seeder
{
    public function run(): void
    {
        DB::table('general_settings')->updateOrInsert(
            ['id' => 1],
            [
                'company_name' => config('app.name'),
                'timezone' => config('app.timezone'),
                'currency' => 'INR',
                'language' => config('app.locale'),
                'date_format' => 'Y-m-d',
                'time_format' => 'H:i',
                'created_at' => now(),
                'updated_at' => now(),
            ],
        );

        DB::table('security_settings')->updateOrInsert(
            ['id' => 1],
            [
                'login_attempts' => config('security.admin_login.max_attempts'),
                'lockout_duration' => config('security.admin_login.decay_seconds'),
                'password_expiry' => 90,
                'minimum_password_length' => 12,
                'two_factor_enabled' => true,
                'session_timeout' => config('session.admin_timeout') * 60,
                'force_https' => app()->isProduction(),
                'jwt_expiry' => 3600,
                'api_rate_limit' => 60,
                'created_at' => now(),
                'updated_at' => now(),
            ],
        );

        DB::table('languages')->updateOrInsert(
            ['code' => 'en'],
            [
                'name' => 'English',
                'locale' => 'en_US',
                'direction' => 'ltr',
                'is_default' => true,
                'is_active' => true,
                'created_at' => now(),
                'updated_at' => now(),
            ],
        );

        foreach (['general', 'security', 'email', 'sms', 'push', 'payment', 'maps', 'storage', 'backup', 'api'] as $group) {
            DB::table('system_settings')->updateOrInsert(
                ['setting_group' => $group, 'setting_key' => 'enabled'],
                [
                    'uuid' => (string) Str::uuid(),
                    'setting_value' => '0',
                    'setting_type' => 'boolean',
                    'description' => Str::title($group).' integration status.',
                    'is_public' => false,
                    'is_encrypted' => false,
                    'updated_at' => now(),
                ],
            );
        }
    }
}
