<?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('users', function (Blueprint $table): void {
            if (! Schema::hasColumn('users', 'cover_hash')) {
                $table->string('cover_hash', 64)->nullable()->after('last_visit_at');
            }

            if (! Schema::hasColumn('users', 'cover_ext')) {
                $table->string('cover_ext', 10)->nullable()->after('cover_hash');
            }

            if (! Schema::hasColumn('users', 'cover_position')) {
                $table->unsignedTinyInteger('cover_position')->default(50)->after('cover_ext');
            }
        });
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table): void {
            if (Schema::hasColumn('users', 'cover_position')) {
                $table->dropColumn('cover_position');
            }

            if (Schema::hasColumn('users', 'cover_ext')) {
                $table->dropColumn('cover_ext');
            }

            if (Schema::hasColumn('users', 'cover_hash')) {
                $table->dropColumn('cover_hash');
            }
        });
    }
};
