"""phase8 calendar+meetings: calendar/cal_event/focus_block/meeting/meeting_action

Revision ID: p8b2c3d4e5f6
Revises: p7a1b2c3d4e5
Create Date: 2026-06-14 01:00:00.000000

"""
from typing import Sequence, Union

import sqlalchemy as sa
import sqlmodel
from alembic import op

revision: str = "p8b2c3d4e5f6"
down_revision: Union[str, Sequence[str], None] = "p7a1b2c3d4e5"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

S = sqlmodel.sql.sqltypes.AutoString


def upgrade() -> None:
    op.create_table(
        "calendar",
        sa.Column("id", S(), nullable=False),
        sa.Column("name", S(), nullable=False),
        sa.Column("tone", S(), nullable=False),
        sa.Column("on", sa.Boolean(), nullable=False),
        sa.Column("sort_order", sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "cal_event",
        sa.Column("id", S(), nullable=False),
        sa.Column("day", sa.Integer(), nullable=False),
        sa.Column("start", S(), nullable=False),
        sa.Column("end", S(), nullable=False),
        sa.Column("title", S(), nullable=False),
        sa.Column("cal", S(), nullable=False),
        sa.Column("loc", S(), nullable=False),
        sa.Column("note", S(), nullable=False),
        sa.Column("soon", sa.Boolean(), nullable=False),
        sa.Column("people", S(), nullable=False),
        sa.Column("sort_order", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["cal"], ["calendar.id"]),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "focus_block",
        sa.Column("id", S(), nullable=False),
        sa.Column("day", sa.Integer(), nullable=False),
        sa.Column("start", S(), nullable=False),
        sa.Column("end", S(), nullable=False),
        sa.Column("title", S(), nullable=False),
        sa.Column("type", S(), nullable=False),
        sa.Column("tag", S(), nullable=False),
        sa.Column("task_id", S(), nullable=True),
        sa.Column("auto", sa.Boolean(), nullable=False),
        sa.Column("sort_order", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["task_id"], ["task.id"]),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "meeting",
        sa.Column("id", S(), nullable=False),
        sa.Column("event_id", S(), nullable=False),
        sa.Column("phase", S(), nullable=False),
        sa.Column("one_on_one", sa.Boolean(), nullable=False),
        sa.Column("meta", S(), nullable=False),
        sa.Column("starts_in", S(), nullable=False),
        sa.Column("summary_json", S(), nullable=False),
        sa.Column("decisions_json", S(), nullable=False),
        sa.Column("agenda_json", S(), nullable=False),
        sa.Column("last_meeting_json", S(), nullable=False),
        sa.Column("last_actions_json", S(), nullable=False),
        sa.Column("insights_json", S(), nullable=False),
        sa.Column("docs_json", S(), nullable=False),
        sa.Column("person_json", S(), nullable=False),
        sa.Column("promises_json", S(), nullable=False),
        sa.Column("signals_json", S(), nullable=False),
        sa.Column("talking_points_json", S(), nullable=False),
        sa.ForeignKeyConstraint(["event_id"], ["cal_event.id"]),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "meeting_action",
        sa.Column("id", S(), nullable=False),
        sa.Column("meeting_id", S(), nullable=True),
        sa.Column("event_id", S(), nullable=True),
        sa.Column("source", S(), nullable=False),
        sa.Column("idx", sa.Integer(), nullable=False),
        sa.Column("text", S(), nullable=False),
        sa.Column("who", S(), nullable=False),
        sa.Column("when_text", S(), nullable=False),
        sa.Column("added", sa.Boolean(), nullable=False),
        sa.Column("materialized_task_id", S(), nullable=True),
        sa.Column("sort_order", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["meeting_id"], ["meeting.id"]),
        sa.ForeignKeyConstraint(["event_id"], ["cal_event.id"]),
        sa.ForeignKeyConstraint(["materialized_task_id"], ["task.id"]),
        sa.PrimaryKeyConstraint("id"),
    )


def downgrade() -> None:
    for t in ("meeting_action", "meeting", "focus_block", "cal_event", "calendar"):
        op.drop_table(t)
