<?php

declare(strict_types=1);

namespace App\Domain\Media\Migrations;

use App\Framework\Database\ConnectionInterface;
use App\Framework\Database\Migration\Migration;
use App\Framework\Database\Migration\MigrationVersion;
use App\Framework\Database\Schema\Blueprint;
use App\Framework\Database\Schema\Schema;

final class CreateImagesTable implements Migration
{
    public function up(ConnectionInterface $connection): void
    {
        $schema = new Schema($connection);

        $schema->createIfNotExists('images', function (Blueprint $table) {
            $table->string('ulid', 26)->primary();
            $table->string('filename', 255);
            $table->string('original_filename', 255);
            $table->string('mime_type', 100);
            $table->bigInteger('file_size');
            $table->integer('width');
            $table->integer('height');
            $table->string('hash', 255);
            $table->string('path', 500);
            $table->text('alt_text');
            $table->timestamp('created_at')->useCurrent();
            $table->timestamp('updated_at')->nullable();

            $table->unique('hash', 'uk_images_hash');
            $table->unique('ulid', 'uk_images_ulid');

            $table->engine('InnoDB');
            $table->charset('utf8mb4');
            $table->collation('utf8mb4_unicode_ci');
        });

        $schema->execute();
    }

    public function down(ConnectionInterface $connection): void
    {
        $schema = new Schema($connection);
        $schema->dropIfExists('images');
        $schema->execute();
    }

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

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