"""initial

Revision ID: 3d15c3cac7b6
Revises: 
Create Date: 2025-07-15 09:43:16.209294

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '3d15c3cac7b6'
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:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('client_groups',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=100), nullable=False),
    sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('event_media',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('media_type', sa.Enum('pdf', 'ppt', 'pptx', 'odp', 'mp4', 'avi', 'mkv', 'mov', 'wmv', 'flv', 'webm', 'mpg', 'mpeg', 'ogv', 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'svg', 'html', name='mediatype'), nullable=False),
    sa.Column('url', sa.String(length=255), nullable=False),
    sa.Column('file_path', sa.String(length=255), nullable=True),
    sa.Column('message_content', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('users',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('username', sa.String(length=50), nullable=False),
    sa.Column('password_hash', sa.String(length=128), nullable=False),
    sa.Column('role', sa.Enum('user', 'admin', 'superadmin', name='userrole'), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
    sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
    op.create_table('clients',
    sa.Column('uuid', sa.String(length=36), nullable=False),
    sa.Column('hardware_hash', sa.String(length=64), nullable=False),
    sa.Column('location', sa.String(length=100), nullable=True),
    sa.Column('ip_address', sa.String(length=45), nullable=True),
    sa.Column('registration_time', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
    sa.Column('last_alive', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('group_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['group_id'], ['client_groups.id'], ),
    sa.PrimaryKeyConstraint('uuid')
    )
    op.create_index(op.f('ix_clients_hardware_hash'), 'clients', ['hardware_hash'], unique=False)
    op.create_index(op.f('ix_clients_ip_address'), 'clients', ['ip_address'], unique=False)
    op.create_table('events',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('group_id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=100), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('start', sa.TIMESTAMP(timezone=True), nullable=False),
    sa.Column('end', sa.TIMESTAMP(timezone=True), nullable=False),
    sa.Column('event_type', sa.Enum('presentation', 'website', 'video', 'message', 'other', 'webuntis', name='eventtype'), nullable=False),
    sa.Column('event_media_id', sa.Integer(), nullable=True),
    sa.Column('autoplay', sa.Boolean(), nullable=True),
    sa.Column('loop', sa.Boolean(), nullable=True),
    sa.Column('volume', sa.Float(), nullable=True),
    sa.Column('slideshow_interval', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
    sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
    sa.Column('created_by', sa.Integer(), nullable=False),
    sa.Column('updated_by', sa.Integer(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.ForeignKeyConstraint(['created_by'], ['users.id'], ),
    sa.ForeignKeyConstraint(['event_media_id'], ['event_media.id'], ),
    sa.ForeignKeyConstraint(['group_id'], ['client_groups.id'], ),
    sa.ForeignKeyConstraint(['updated_by'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_events_end'), 'events', ['end'], unique=False)
    op.create_index(op.f('ix_events_group_id'), 'events', ['group_id'], unique=False)
    op.create_index(op.f('ix_events_start'), 'events', ['start'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_events_start'), table_name='events')
    op.drop_index(op.f('ix_events_group_id'), table_name='events')
    op.drop_index(op.f('ix_events_end'), table_name='events')
    op.drop_table('events')
    op.drop_index(op.f('ix_clients_ip_address'), table_name='clients')
    op.drop_index(op.f('ix_clients_hardware_hash'), table_name='clients')
    op.drop_table('clients')
    op.drop_index(op.f('ix_users_username'), table_name='users')
    op.drop_table('users')
    op.drop_table('event_media')
    op.drop_table('client_groups')
    # ### end Alembic commands ###
