"""Create ``codal_statements`` table for codal-parser output.  Revision ID: 0016"""

from __future__ import annotations

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

VERSION = "0016"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="codal_statements_0001",
            description="Create codal_statements table for codal.ir financial statement discovery",
            up=(
                MigrationBuilder("codal_statements")
                .uuid("id", primary_key=True, nullable=False)
                .text("url", nullable=False)
                .text("statement_type", nullable=True)
                .text("source_page_url", nullable=True)
                .text("anchor_text", nullable=True)
                .timestamp("created_at", nullable=True, default="now()")
                .timestamp("updated_at", nullable=True, default="now()")
                .index(["url"], unique=True)
                .index(["statement_type"])
                .create_table()
            ),
            down=MigrationBuilder("codal_statements").drop_table(),
        ),
    ]
