<?php

namespace Database\Seeders;

use App\Models\Setting;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class SettingsSeeder extends Seeder
{
    /**
     * @var array<string, array{value: string|null, is_encrypted?: bool}>
     */
    private array $defaults = [
        'property_name' => ['value' => 'Venue Events Manager'],
        'timezone' => ['value' => 'Africa/Nairobi'],
        'currency' => ['value' => 'KES'],
        'currency_symbol' => ['value' => 'KES'],
        'date_format' => ['value' => 'd/m/Y'],
        'time_format' => ['value' => 'H:i'],
        'default_tax' => ['value' => '16'],
        'default_service_charge' => ['value' => '0'],
        'default_quotation_validity_days' => ['value' => '14'],
        'default_hold_duration_hours' => ['value' => '48'],
        'default_deposit_percentage' => ['value' => '30'],
        'booking_prefix' => ['value' => 'BKG'],
        'quotation_prefix' => ['value' => 'QTN'],
        'invoice_prefix' => ['value' => 'INV'],
        'payment_prefix' => ['value' => 'RCT'],
        'number_padding' => ['value' => '6'],
        'company_address' => ['value' => ''],
        'company_phone' => ['value' => ''],
        'company_email' => ['value' => ''],
        'receipt_footer' => ['value' => 'Thank you for your business.'],
        'invoice_terms' => ['value' => 'Payment is due within the agreed terms.'],
        'quotation_terms' => ['value' => 'This quotation is valid for the period stated above.'],
        'attachment_max_size_mb' => ['value' => '10'],
        'schema_version' => ['value' => '1.0.0'],
    ];

    public function run(): void
    {
        DB::transaction(function (): void {
            foreach ($this->defaults as $key => $meta) {
                Setting::query()->updateOrCreate(
                    ['key' => $key],
                    [
                        'value' => $meta['value'],
                        'is_encrypted' => $meta['is_encrypted'] ?? false,
                    ],
                );
            }
        });
    }
}
