"""Create ``codal_media`` table for storing media inspection results.

Revision ID: 0023
"""
from __future__ import annotations

from repo_core.migrations.builder import MigrationBuilder
from repo_core.migrations.runner import Migration

VERSION = "0023"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="codal_media_0001",
            description="Create codal_media table for media inspection results",
            up=(
                MigrationBuilder("codal_media")
                .uuid("id", primary_key=True, nullable=False)
                .uuid("web_media_id", nullable=True)
                .text("source_url", nullable=True)
                .text("source_filename", nullable=True)
                .text("stored_filename", nullable=True)
                .text("content_type", nullable=True)
                .text("content_disposition", nullable=True)
                .text("extension_raw", nullable=True)
                .text("extension_detected", nullable=True)
                .text("format", nullable=True)
                .text("sha256", nullable=True)
                .bigint("byte_size", nullable=True)
                .text("etag", nullable=True)
                .text("final_url", nullable=True)
                .integer("status_code", nullable=True)
                .integer("latency_ms", nullable=True)
                .text("request_method", nullable=True)
                .integer("retry_count", nullable=True)
                .jsonb("redirect_chain", nullable=True)
                .timestamp("downloaded_at", nullable=True)
                .timestamp("requested_at", nullable=True)
                .timestamp("discovered_at", nullable=True)
                .integer("pages", nullable=True)
                .text("author", nullable=True)
                .text("subject", nullable=True)
                .text("creator", nullable=True)
                .text("producer", nullable=True)
                .text("encoding", nullable=True)
                .jsonb("sheets", nullable=True)
                .integer("width", nullable=True)
                .integer("height", nullable=True)
                .uuid("parent_id", nullable=True)
                .timestamp("created_at", nullable=False, default="now()")
                .timestamp("updated_at", nullable=False, default="now()")
                .index(["web_media_id"], unique=True)
                .create_table()
            ),
            down=MigrationBuilder("codal_media").drop_table(),
        ),
    ]
