<?php

declare(strict_types=1);

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

return new class extends Migration {
    public function up(): void
    {
        if (! Schema::hasTable('user_profiles')) {
            return;
        }

        Schema::table('user_profiles', function (Blueprint $table): void {
            if (! Schema::hasColumn('user_profiles', 'mature_content_visibility')) {
                $table->string('mature_content_visibility', 12)->default('blur');
            }
            if (! Schema::hasColumn('user_profiles', 'mature_content_warning_enabled')) {
                $table->boolean('mature_content_warning_enabled')->default(true);
            }
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('user_profiles')) {
            return;
        }

        Schema::table('user_profiles', function (Blueprint $table): void {
            foreach (['mature_content_visibility', 'mature_content_warning_enabled'] as $column) {
                if (Schema::hasColumn('user_profiles', $column)) {
                    $table->dropColumn($column);
                }
            }
        });
    }
};