"""auto update

Revision ID: b9c43953d04a
Revises: 08dcf1b5bd8d
Create Date: 2026-04-30 03:03:08.754126

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'b9c43953d04a'
down_revision: Union[str, Sequence[str], None] = '08dcf1b5bd8d'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('agent_availability',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('seat_id', sa.Integer(), nullable=False),
    sa.Column('status', sa.String(), nullable=False),
    sa.Column('last_heartbeat_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_agent_availability_id'), 'agent_availability', ['id'], unique=False)
    op.create_table('chat_analytics_daily',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('date', sa.Date(), nullable=False),
    sa.Column('department_id', sa.Integer(), nullable=True),
    sa.Column('total_chats', sa.Integer(), nullable=True),
    sa.Column('ai_resolved', sa.Integer(), nullable=True),
    sa.Column('human_resolved', sa.Integer(), nullable=True),
    sa.Column('avg_first_response_sec', sa.Integer(), nullable=True),
    sa.Column('avg_resolution_sec', sa.Integer(), nullable=True),
    sa.Column('sla_breaches', sa.Integer(), nullable=True),
    sa.Column('escalations', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_chat_analytics_daily_id'), 'chat_analytics_daily', ['id'], unique=False)
    op.create_table('chat_attachments',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('conversation_id', sa.Integer(), nullable=False),
    sa.Column('message_id', sa.Integer(), nullable=True),
    sa.Column('object_key', sa.String(), nullable=False),
    sa.Column('file_name', sa.String(), nullable=False),
    sa.Column('mime_type', sa.String(), nullable=True),
    sa.Column('size_bytes', sa.Integer(), nullable=True),
    sa.Column('url', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_chat_attachments_id'), 'chat_attachments', ['id'], unique=False)
    op.create_table('chat_conversations',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.String(), nullable=True),
    sa.Column('whmcs_client_id', sa.Integer(), nullable=True),
    sa.Column('visitor_name', sa.String(), nullable=True),
    sa.Column('visitor_email', sa.String(), nullable=True),
    sa.Column('department_id', sa.Integer(), nullable=True),
    sa.Column('assigned_seat_id', sa.Integer(), nullable=True),
    sa.Column('status', sa.String(), nullable=False),
    sa.Column('priority', sa.String(), nullable=False),
    sa.Column('sla_due_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('linked_whmcs_service_id', sa.Integer(), nullable=True),
    sa.Column('linked_whmcs_invoice_id', sa.Integer(), nullable=True),
    sa.Column('linked_whmcs_domain_id', sa.Integer(), nullable=True),
    sa.Column('linked_ticket_id', sa.Integer(), nullable=True),
    sa.Column('ai_summary', sa.String(), nullable=True),
    sa.Column('last_message_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('subject', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_chat_conversations_id'), 'chat_conversations', ['id'], unique=False)
    op.create_table('chat_messages',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('conversation_id', sa.Integer(), nullable=False),
    sa.Column('sender_type', sa.String(), nullable=False),
    sa.Column('sender_seat_id', sa.Integer(), nullable=True),
    sa.Column('sender_name', sa.String(), nullable=True),
    sa.Column('content', sa.String(), nullable=False),
    sa.Column('attachments', sa.String(), nullable=True),
    sa.Column('is_internal_note', sa.Boolean(), nullable=True),
    sa.Column('ai_confidence', sa.Float(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_chat_messages_id'), 'chat_messages', ['id'], unique=False)
    op.create_table('chat_routing_rules',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('priority', sa.Integer(), nullable=False),
    sa.Column('match_conditions', sa.String(), nullable=True),
    sa.Column('target_department_id', sa.Integer(), nullable=True),
    sa.Column('target_seat_id', sa.Integer(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_chat_routing_rules_id'), 'chat_routing_rules', ['id'], unique=False)
    op.create_table('kb_articles',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('title', sa.String(), nullable=False),
    sa.Column('slug', sa.String(), nullable=True),
    sa.Column('source', sa.String(), nullable=False),
    sa.Column('source_url', sa.String(), nullable=True),
    sa.Column('content', sa.String(), nullable=False),
    sa.Column('tags', sa.String(), nullable=True),
    sa.Column('is_published', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_kb_articles_id'), 'kb_articles', ['id'], unique=False)
    op.create_table('support_departments',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('slug', sa.String(), nullable=False),
    sa.Column('description', sa.String(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_support_departments_id'), 'support_departments', ['id'], unique=False)
    op.create_table('support_seats',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.String(), nullable=True),
    sa.Column('display_name', sa.String(), nullable=False),
    sa.Column('email', sa.String(), nullable=False),
    sa.Column('role', sa.String(), nullable=False),
    sa.Column('department_id', sa.Integer(), nullable=True),
    sa.Column('status', sa.String(), nullable=True),
    sa.Column('chat_limit', sa.Integer(), nullable=True),
    sa.Column('working_hours', sa.String(), nullable=True),
    sa.Column('permissions', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_support_seats_id'), 'support_seats', ['id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_support_seats_id'), table_name='support_seats')
    op.drop_table('support_seats')
    op.drop_index(op.f('ix_support_departments_id'), table_name='support_departments')
    op.drop_table('support_departments')
    op.drop_index(op.f('ix_kb_articles_id'), table_name='kb_articles')
    op.drop_table('kb_articles')
    op.drop_index(op.f('ix_chat_routing_rules_id'), table_name='chat_routing_rules')
    op.drop_table('chat_routing_rules')
    op.drop_index(op.f('ix_chat_messages_id'), table_name='chat_messages')
    op.drop_table('chat_messages')
    op.drop_index(op.f('ix_chat_conversations_id'), table_name='chat_conversations')
    op.drop_table('chat_conversations')
    op.drop_index(op.f('ix_chat_attachments_id'), table_name='chat_attachments')
    op.drop_table('chat_attachments')
    op.drop_index(op.f('ix_chat_analytics_daily_id'), table_name='chat_analytics_daily')
    op.drop_table('chat_analytics_daily')
    op.drop_index(op.f('ix_agent_availability_id'), table_name='agent_availability')
    op.drop_table('agent_availability')
    # ### end Alembic commands ###