<?php

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

class AddBrandColorsToSettingsTable extends Migration
{
    public function up()
    {
        Schema::table('settings', function (Blueprint $table) {
            if (!Schema::hasColumn('settings', 'brand_primary_color')) {
                $table->string('brand_primary_color', 20)->default('#f7931a')->after('twak');
            }
            if (!Schema::hasColumn('settings', 'brand_secondary_color')) {
                $table->string('brand_secondary_color', 20)->default('#155c9d')->after('brand_primary_color');
            }
            if (!Schema::hasColumn('settings', 'brand_accent_color')) {
                $table->string('brand_accent_color', 20)->default('#0f766e')->after('brand_secondary_color');
            }
            if (!Schema::hasColumn('settings', 'brand_dark_color')) {
                $table->string('brand_dark_color', 20)->default('#102033')->after('brand_accent_color');
            }
            if (!Schema::hasColumn('settings', 'brand_light_color')) {
                $table->string('brand_light_color', 20)->default('#fff7ed')->after('brand_dark_color');
            }
            if (!Schema::hasColumn('settings', 'brand_success_color')) {
                $table->string('brand_success_color', 20)->default('#16a34a')->after('brand_light_color');
            }
            if (!Schema::hasColumn('settings', 'brand_warning_color')) {
                $table->string('brand_warning_color', 20)->default('#f59e0b')->after('brand_success_color');
            }
            if (!Schema::hasColumn('settings', 'brand_danger_color')) {
                $table->string('brand_danger_color', 20)->default('#dc2626')->after('brand_warning_color');
            }
        });
    }

    public function down()
    {
        Schema::table('settings', function (Blueprint $table) {
            foreach ([
                'brand_primary_color',
                'brand_secondary_color',
                'brand_accent_color',
                'brand_dark_color',
                'brand_light_color',
                'brand_success_color',
                'brand_warning_color',
                'brand_danger_color',
            ] as $column) {
                if (Schema::hasColumn('settings', $column)) {
                    $table->dropColumn($column);
                }
            }
        });
    }
}
