"""init.

Revision ID: 5ad873484aa3
Revises: 
Create Date: 2024-07-25 13:09:44.450321

"""
from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "5ad873484aa3"
down_revision: str | None = None
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Upgrade database to this revision from previous."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "caption",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column(
            "model",
            sa.String(),
            nullable=False,
            comment="Name of model used to generate the caption",
        ),
        sa.Column(
            "frame_id",
            sa.Integer(),
            nullable=False,
            comment="The 0-based frame id of video for caption",
        ),
        sa.Column("caption", sa.String(), nullable=False, comment="Frame caption"),
        sa.Column(
            "timestamp",
            sa.Float(),
            nullable=False,
            comment="Frame timestamp in seconds",
        ),
        sa.Column(
            "caption_type", sa.String(), nullable=False, comment="The type of caption"
        ),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=False,
            comment="Timestamp when row is inserted",
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=False,
            comment="Timestamp when row is updated",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_caption")),
    )
    op.create_table(
        "media",
        sa.Column(
            "id",
            sa.String(length=36),
            nullable=False,
            comment="Unique identifier for the media",
        ),
        sa.Column(
            "media_type", sa.String(), nullable=False, comment="The type of media"
        ),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=False,
            comment="Timestamp when row is inserted",
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=False,
            comment="Timestamp when row is updated",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_media")),
    )
    op.create_table(
        "tasks",
        sa.Column("id", sa.UUID(), nullable=False, comment="Task ID"),
        sa.Column(
            "endpoint",
            sa.String(),
            nullable=False,
            comment="The endpoint to which the task is assigned",
        ),
        sa.Column("data", sa.PickleType(), nullable=False, comment="Data for the task"),
        sa.Column(
            "status",
            sa.Enum(
                "CREATED",
                "ASSIGNED",
                "COMPLETED",
                "RUNNING",
                "FAILED",
                "NOT_FINISHED",
                name="status",
            ),
            nullable=False,
            comment="Status of the task",
        ),
        sa.Column(
            "priority",
            sa.Integer(),
            nullable=False,
            comment="Priority of the task (0 is the lowest)",
        ),
        sa.Column(
            "assigned_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=True,
            comment="Timestamp when the task was assigned",
        ),
        sa.Column(
            "completed_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=True,
            comment="Timestamp when the task was completed",
        ),
        sa.Column(
            "progress",
            sa.Float(),
            nullable=False,
            comment="Progress of the task in percentage",
        ),
        sa.Column(
            "result",
            sa.JSON(),
            nullable=True,
            comment="Result of the task in JSON format",
        ),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=False,
            comment="Timestamp when row is inserted",
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=False,
            comment="Timestamp when row is updated",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_tasks")),
    )
    op.create_table(
        "transcript",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column(
            "model",
            sa.String(),
            nullable=False,
            comment="Name of model used to generate transcript",
        ),
        sa.Column(
            "transcript",
            sa.String(),
            nullable=False,
            comment="Full text transcript of media",
        ),
        sa.Column(
            "segments", sa.JSON(), nullable=False, comment="Segments of the transcript"
        ),
        sa.Column(
            "language",
            sa.String(),
            nullable=False,
            comment="Language of the transcript as predicted by model",
        ),
        sa.Column(
            "language_confidence",
            sa.Float(),
            nullable=False,
            comment="Confidence score of language prediction",
        ),
        sa.Column(
            "transcript_type",
            sa.String(),
            nullable=False,
            comment="The type of transcript",
        ),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=False,
            comment="Timestamp when row is inserted",
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=False,
            comment="Timestamp when row is updated",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_transcript")),
    )
    op.create_table(
        "video",
        sa.Column("id", sa.String(length=36), nullable=False),
        sa.Column("path", sa.String(), nullable=True, comment="Path"),
        sa.Column("url", sa.String(), nullable=True, comment="URL"),
        sa.Column("title", sa.String(), nullable=True, comment="Title"),
        sa.Column("description", sa.String(), nullable=True, comment="Description"),
        sa.ForeignKeyConstraint(["id"], ["media.id"], name=op.f("fk_video_id_media")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_video")),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade database from this revision to previous."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("video")
    op.drop_table("transcript")
    op.drop_table("tasks")
    op.drop_table("media")
    op.drop_table("caption")
    # ### end Alembic commands ###
