"""initial_schema

Revision ID: 0a8788565a3e
Revises: 
Create Date: 2026-02-26 17:46:58.441718

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
import sqlmodel


# revision identifiers, used by Alembic.
revision: str = '0a8788565a3e'
down_revision: Union[str, None] = None
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('async_presentation_generation_tasks',
    sa.Column('id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('status', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('message', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('error', sa.JSON(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.Column('data', sa.JSON(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('clients',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('slug', sa.String(), nullable=True),
    sa.Column('logo_path', sa.String(), nullable=True),
    sa.Column('retention_days', sa.Integer(), nullable=True),
    sa.Column('review_policy', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_clients_slug'), 'clients', ['slug'], unique=True)
    op.create_table('imageasset',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('is_uploaded', sa.Boolean(), nullable=False),
    sa.Column('path', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('extras', sa.JSON(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('keyvaluesqlmodel',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('key', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('value', sa.JSON(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_keyvaluesqlmodel_key'), 'keyvaluesqlmodel', ['key'], unique=False)
    op.create_table('ollamapullstatus',
    sa.Column('id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('last_updated', sa.DateTime(), nullable=True),
    sa.Column('status', sa.JSON(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('presentation_layout_codes',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('presentation', sa.Uuid(), nullable=False),
    sa.Column('layout_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('layout_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('layout_code', sa.Text(), nullable=True),
    sa.Column('fonts', sa.JSON(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_presentation_layout_codes_presentation'), 'presentation_layout_codes', ['presentation'], unique=False)
    op.create_table('templates',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('users',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('azure_oid', sa.String(), nullable=True),
    sa.Column('email', sa.String(), nullable=True),
    sa.Column('display_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('role', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('last_login_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_azure_oid'), 'users', ['azure_oid'], unique=True)
    op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
    op.create_table('webhook_subscriptions',
    sa.Column('id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('url', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('secret', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('event', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_webhook_subscriptions_event'), 'webhook_subscriptions', ['event'], unique=False)
    op.create_table('audit_logs',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('user_id', sa.Uuid(), nullable=True),
    sa.Column('action', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('resource_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('resource_id', sa.Uuid(), nullable=True),
    sa.Column('client_id', sa.Uuid(), nullable=True),
    sa.Column('details', sa.JSON(), nullable=True),
    sa.Column('ip_address', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_audit_logs_created_at'), 'audit_logs', ['created_at'], unique=False)
    op.create_table('brand_configs',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('client_id', sa.Uuid(), nullable=True),
    sa.Column('primary_colors', sa.JSON(), nullable=True),
    sa.Column('secondary_colors', sa.JSON(), nullable=True),
    sa.Column('fonts', sa.JSON(), nullable=True),
    sa.Column('logo_paths', sa.JSON(), nullable=True),
    sa.Column('voice_rules', sa.String(), nullable=True),
    sa.Column('voice_examples', sa.JSON(), nullable=True),
    sa.Column('guideline_doc_path', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['client_id'], ['clients.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('client_id')
    )
    op.create_table('master_decks',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('client_id', sa.Uuid(), nullable=True),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('description', sa.String(), nullable=True),
    sa.Column('original_file_path', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('thumbnail_path', sa.String(), nullable=True),
    sa.Column('parsed_config', sa.JSON(), nullable=True),
    sa.Column('layouts', sa.JSON(), nullable=True),
    sa.Column('parse_status', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['client_id'], ['clients.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('teams',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('client_id', sa.Uuid(), nullable=True),
    sa.Column('is_default', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['client_id'], ['clients.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('presentations',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('content', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('n_slides', sa.Integer(), nullable=False),
    sa.Column('language', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('title', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('file_paths', sa.JSON(), nullable=True),
    sa.Column('outlines', sa.JSON(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('layout', sa.JSON(), nullable=True),
    sa.Column('structure', sa.JSON(), nullable=True),
    sa.Column('instructions', sa.String(), nullable=True),
    sa.Column('tone', sa.String(), nullable=True),
    sa.Column('verbosity', sa.String(), nullable=True),
    sa.Column('include_table_of_contents', sa.Boolean(), nullable=True),
    sa.Column('include_title_slide', sa.Boolean(), nullable=True),
    sa.Column('web_search', sa.Boolean(), nullable=True),
    sa.Column('owner_id', sa.Uuid(), nullable=True),
    sa.Column('client_id', sa.Uuid(), nullable=True),
    sa.Column('master_deck_id', sa.Uuid(), nullable=True),
    sa.Column('status', sa.String(), nullable=True),
    sa.Column('review_comment', sa.String(), nullable=True),
    sa.Column('source_type', sa.String(), nullable=True),
    sa.Column('is_saved', sa.Boolean(), nullable=True),
    sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
    sa.ForeignKeyConstraint(['client_id'], ['clients.id'], ),
    sa.ForeignKeyConstraint(['master_deck_id'], ['master_decks.id'], ),
    sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('team_memberships',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('user_id', sa.Uuid(), nullable=True),
    sa.Column('team_id', sa.Uuid(), nullable=True),
    sa.Column('assigned_by', sa.Uuid(), nullable=True),
    sa.Column('assigned_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['assigned_by'], ['users.id'], name='fk_assigned_by'),
    sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('user_id', 'team_id')
    )
    op.create_index(op.f('ix_team_memberships_team_id'), 'team_memberships', ['team_id'], unique=False)
    op.create_index(op.f('ix_team_memberships_user_id'), 'team_memberships', ['user_id'], unique=False)
    op.create_table('jobs',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('user_id', sa.Uuid(), nullable=True),
    sa.Column('client_id', sa.Uuid(), nullable=True),
    sa.Column('presentation_id', sa.Uuid(), nullable=True),
    sa.Column('job_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('status', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('progress', sa.Integer(), nullable=True),
    sa.Column('progress_message', sa.String(), nullable=True),
    sa.Column('error_message', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('started_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True),
    sa.ForeignKeyConstraint(['client_id'], ['clients.id'], ),
    sa.ForeignKeyConstraint(['presentation_id'], ['presentations.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('slides',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('presentation', sa.Uuid(), nullable=True),
    sa.Column('layout_group', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('layout', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('index', sa.Integer(), nullable=False),
    sa.Column('content', sa.JSON(), nullable=True),
    sa.Column('html_content', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('speaker_note', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('properties', sa.JSON(), nullable=True),
    sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
    sa.ForeignKeyConstraint(['presentation'], ['presentations.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_slides_presentation'), 'slides', ['presentation'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_slides_presentation'), table_name='slides')
    op.drop_table('slides')
    op.drop_table('jobs')
    op.drop_index(op.f('ix_team_memberships_user_id'), table_name='team_memberships')
    op.drop_index(op.f('ix_team_memberships_team_id'), table_name='team_memberships')
    op.drop_table('team_memberships')
    op.drop_table('presentations')
    op.drop_table('teams')
    op.drop_table('master_decks')
    op.drop_table('brand_configs')
    op.drop_index(op.f('ix_audit_logs_created_at'), table_name='audit_logs')
    op.drop_table('audit_logs')
    op.drop_index(op.f('ix_webhook_subscriptions_event'), table_name='webhook_subscriptions')
    op.drop_table('webhook_subscriptions')
    op.drop_index(op.f('ix_users_email'), table_name='users')
    op.drop_index(op.f('ix_users_azure_oid'), table_name='users')
    op.drop_table('users')
    op.drop_table('templates')
    op.drop_index(op.f('ix_presentation_layout_codes_presentation'), table_name='presentation_layout_codes')
    op.drop_table('presentation_layout_codes')
    op.drop_table('ollamapullstatus')
    op.drop_index(op.f('ix_keyvaluesqlmodel_key'), table_name='keyvaluesqlmodel')
    op.drop_table('keyvaluesqlmodel')
    op.drop_table('imageasset')
    op.drop_index(op.f('ix_clients_slug'), table_name='clients')
    op.drop_table('clients')
    op.drop_table('async_presentation_generation_tasks')
    # ### end Alembic commands ###
