"""PostgreSQL migration for virtual numbers and SMS history."""

from __future__ import annotations

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

VERSION = "0002"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="virtual_numbers_0001",
            description="Create virtual_numbers and number_sms tables",
            up=(
                MigrationBuilder("virtual_numbers")
                .uuid("id", primary_key=True, nullable=False)
                .text("number", nullable=False)
                .text("provider_number_id", nullable=True)
                .text("country", nullable=False)
                .text("operator", nullable=True)
                .text("account_type", nullable=False)
                .float_("price", nullable=True)
                .timestamp("expires_at", nullable=True)
                .text("provider", nullable=False, default="'5sim'")
                .text("status", nullable=False, default="'active'")
                .timestamp("created_at", nullable=True, default="now()")
                .timestamp("updated_at", nullable=True, default="now()")
                .index(["account_type"])
                .index(["country"])
                .index(["expires_at"])
                .create_table()
            ),
            down=MigrationBuilder("virtual_numbers").drop_table(),
        ),
        Migration(
            version="number_sms_0001",
            description="Create number_sms table",
            up=(
                MigrationBuilder("number_sms")
                .uuid("id", primary_key=True, nullable=False)
                .uuid("number_id", nullable=False)
                .timestamp("sms_created_at", nullable=True)
                .timestamp("sms_delivery_date", nullable=True)
                .text("sender", nullable=True)
                .text("text", nullable=True)
                .text("code", nullable=True)
                .timestamp("created_at", nullable=True, default="now()")
                .timestamp("updated_at", nullable=True, default="now()")
                .index(["number_id"])
                .foreign_key("number_id", "virtual_numbers")
                .create_table()
            ),
            down=MigrationBuilder("number_sms").drop_table(),
        ),
    ]
