<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('website_type', function (Blueprint $table): void {
            $table->string('dominio')->nullable()->unique()->after('nombre');
            $table->string('primary_color')->nullable()->after('dominio');
            $table->string('secondary_color')->nullable()->after('primary_color');
            $table->string('danger_color')->nullable()->after('secondary_color');
            $table->string('success_color')->nullable()->after('danger_color');
            $table->string('warning_color')->nullable()->after('success_color');
            $table->string('body_color')->nullable()->after('warning_color');
            $table->string('darker_body_color')->nullable()->after('body_color');
            $table->string('surface_color')->nullable()->after('darker_body_color');
            $table->string('background_color')->nullable()->after('surface_color');
            $table->string('border_color')->nullable()->after('background_color');
            $table->string('login_header_footer_color')->nullable()->after('border_color');
            $table->unsignedBigInteger('site_logo')->nullable()->after('login_header_footer_color');

            $table->foreign('site_logo')
                ->references('id')
                ->on('attachments')
                ->nullOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('website_type', function (Blueprint $table): void {
            if (Schema::getConnection()->getDriverName() !== 'sqlite') {
                $table->dropForeign(['site_logo']);
            }

            $table->dropColumn([
                'dominio',
                'primary_color',
                'secondary_color',
                'danger_color',
                'success_color',
                'warning_color',
                'body_color',
                'darker_body_color',
                'surface_color',
                'background_color',
                'border_color',
                'login_header_footer_color',
                'site_logo',
            ]);
        });
    }
};
