<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('settings', function (Blueprint $table) {
            $table->id();
            $table->string('key')->unique();
            $table->longText('value')->nullable();
            $table->timestamps();
        });

        $defaults = [
            'website_name' => 'Accessway Express Courier',
            'website_title' => 'Accessway Express Courier Services',
            'website_url' => 'http://127.0.0.1:8000',
            'office_address' => '26 Upper Brook St, London W1K 7QE, United Kingdom.',
            'whatsapp' => '',
            'telegram' => '',
            'smartsupp_code' => '',
            'year_started' => '2001',
            'installation_type' => 'Main-Domain',
            'logo_path' => '',
            'favicon_path' => '',
            'mail_mailer' => 'smtp',
            'mail_from' => 'info@accesswaysexpresscourier.com',
            'mail_from_name' => 'Accessway Express Courier',
            'smtp_host' => '',
            'smtp_port' => '587',
            'smtp_encryption' => 'tls',
            'smtp_username' => '',
            'smtp_password' => '',
            'customs_notice_enabled' => '1',
            'customs_notice_text' => 'Note: To turn on Customs Clearance Document Required.',
            'contact_email' => 'info@accesswaysexpresscourier.com',
            'website_currency' => '$',
            'homepage_redirect' => '',
        ];

        $now = now();
        foreach ($defaults as $key => $value) {
            DB::table('settings')->insert([
                'key' => $key,
                'value' => $value,
                'created_at' => $now,
                'updated_at' => $now,
            ]);
        }
    }

    public function down(): void
    {
        Schema::dropIfExists('settings');
    }
};
