"""add coaching tables and rider coaching fields

Revision ID: 4c6a3c01542f
Revises: 928b78044640
Create Date: 2026-03-16 14:26:46.753457

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = '4c6a3c01542f'
down_revision: Union[str, None] = '928b78044640'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('coaching_chats',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('rider_id', sa.UUID(), nullable=False),
    sa.Column('chat_type', sa.String(length=50), nullable=False),
    sa.Column('messages_json', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
    sa.Column('status', sa.String(length=20), nullable=False),
    sa.Column('context_snapshot', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.ForeignKeyConstraint(['rider_id'], ['riders.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('riders', sa.Column('coaching_profile', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
    op.add_column('riders', sa.Column('onboarding_completed', sa.Boolean(), server_default=sa.text('false'), nullable=False))
    op.add_column('training_plans', sa.Column('status', sa.String(length=20), server_default=sa.text("'active'"), nullable=False))
    op.add_column('training_plans', sa.Column('onboarding_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
    op.add_column('training_plans', sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False))
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('training_plans', 'updated_at')
    op.drop_column('training_plans', 'onboarding_data')
    op.drop_column('training_plans', 'status')
    op.drop_column('riders', 'onboarding_completed')
    op.drop_column('riders', 'coaching_profile')
    op.drop_table('coaching_chats')
    # ### end Alembic commands ###
