"""Create publisher subpage tables.  Revision ID: 0022

- ``codal_publisher_contacts`` — contact info (one per publisher)
- ``codal_publisher_board`` — board members (multiple per publisher)
- ``codal_publisher_capital`` — capital increase events (multiple per publisher)
"""

from __future__ import annotations

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

VERSION = "0022"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="codal_publisher_contacts_0001",
            description="Create codal_publisher_contacts table",
            up=(
                MigrationBuilder("codal_publisher_contacts")
                .bigint("publisher_id", primary_key=True, nullable=False)
                .text("factory_address", nullable=True)
                .text("factory_phone", nullable=True)
                .text("factory_fax", nullable=True)
                .text("stock_affairs_address", nullable=True)
                .text("stock_affairs_phone", nullable=True)
                .text("stock_affairs_fax", nullable=True)
                .text("central_office_address", nullable=True)
                .text("central_office_phone", nullable=True)
                .text("central_office_fax", nullable=True)
                .text("email", nullable=True)
                .text("website", nullable=True)
                .text("phone", nullable=True)
                .text("fax", nullable=True)
                .timestamp("created_at", nullable=True, default="now()")
                .timestamp("updated_at", nullable=True, default="now()")
                .create_table()
            ),
            down=MigrationBuilder("codal_publisher_contacts").drop_table(),
        ),
        Migration(
            version="codal_publisher_board_0001",
            description="Create codal_publisher_board table",
            up=(
                MigrationBuilder("codal_publisher_board")
                .uuid("id", primary_key=True, nullable=False)
                .bigint("publisher_id", nullable=False)
                .text("name", nullable=True)
                .text("position", nullable=True)
                .boolean("is_employee", nullable=False, default=False)
                .boolean("is_legal_representative", nullable=False, default=False)
                .timestamp("created_at", nullable=True, default="now()")
                .timestamp("updated_at", nullable=True, default="now()")
                .index(["publisher_id"])
                .create_table()
            ),
            down=MigrationBuilder("codal_publisher_board").drop_table(),
        ),
        Migration(
            version="codal_publisher_capital_0001",
            description="Create codal_publisher_capital table",
            up=(
                MigrationBuilder("codal_publisher_capital")
                .uuid("id", primary_key=True, nullable=False)
                .bigint("publisher_id", nullable=False)
                .text("event_date", nullable=True)
                .text("stage", nullable=True)
                .text("description", nullable=True)
                .text("amount", nullable=True)
                .text("percentage", nullable=True)
                .timestamp("created_at", nullable=True, default="now()")
                .timestamp("updated_at", nullable=True, default="now()")
                .index(["publisher_id"])
                .create_table()
            ),
            down=MigrationBuilder("codal_publisher_capital").drop_table(),
        ),
    ]
