<?php

declare(strict_types=1);

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
{
    /**
     * Default seed rows — also called from BrandingController::reset().
     */
    public static function seedDefaults(): void
    {
        $defaults = [
            'brand_name' => 'Onoxsoft Panel',
            'brand_tagline' => 'Kontrol Paneli',
            'primary_color' => '#4f46e5',
            'accent_color' => '#10b981',
            'logo_url' => '',
            'favicon_url' => '',
            'login_bg_url' => '',
            'support_email' => '',
            'support_phone' => '',
            'custom_css' => '',
            'custom_footer_html' => '',
            'hide_powered_by' => '0',
        ];

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

    public function up(): void
    {
        Schema::create('brand_settings', function (Blueprint $table) {
            $table->id();
            $table->string('key')->unique();
            $table->text('value')->nullable();
            $table->timestamps();
        });

        self::seedDefaults();
    }

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