<?php

declare(strict_types=1);

namespace App\Domain\User\Migrations;

use App\Framework\Database\ConnectionInterface;
use App\Framework\Database\Migration\Migration;
use App\Framework\Database\Migration\MigrationVersion;
use App\Framework\Database\Platform\SchemaBuilderFactory;
use App\Framework\Database\Platform\ValueObjects\TableOptions;

final readonly class CreateUsersTable implements Migration
{
    public function up(ConnectionInterface $connection): void
    {
        $schema = SchemaBuilderFactory::create($connection);

        $schema->createTable('users', [
            $schema->id(),
            $schema->binary('ulid', 16)->unique(),
            $schema->string('name', 255)->notNull(),
        ], TableOptions::default()->withComment('User accounts table'));
    }

    public function down(ConnectionInterface $connection): void
    {
        $schema = SchemaBuilderFactory::create($connection);
        $schema->dropTable('users');
    }

    public function getVersion(): MigrationVersion
    {
        return MigrationVersion::fromTimestamp("2024_01_15_000001");
    }

    public function getDescription(): string
    {
        return "Create Users Table";
    }
}
