<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('google_id')->nullable()->unique()->after('email');
            $table->boolean('is_anonymized')->default(false)->after('is_banned');
        });

        // Make password nullable for Google-only accounts.
        // Raw SQL used to avoid requiring doctrine/dbal package.
        DB::statement('ALTER TABLE users MODIFY password VARCHAR(255) NULL');
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['google_id', 'is_anonymized']);
        });

        DB::statement("ALTER TABLE users MODIFY password VARCHAR(255) NOT NULL DEFAULT ''");
    }
};
