<?php

declare(strict_types=1);

namespace App\Domain\Contact\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 CreateContactTable implements Migration
{
    public function up(ConnectionInterface $connection): void
    {
        $schema = SchemaBuilderFactory::create($connection);

        $schema->createTable(
            'contacts',
            [
            $schema->id(),
            $schema->string('name', 255)->notNull(),
            $schema->string('email', 255)->notNull(),
            $schema->text('message')->notNull(),
        ],
            TableOptions::default()
            ->withEngine('InnoDB')
            ->withCharset('utf8mb4')
            ->withCollation('utf8mb4_unicode_ci')
            ->withIfNotExists()
            ->withComment('Contact form submissions table')
        );
    }

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

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

    public function getDescription(): string
    {
        return 'Create contact table';
    }
}
