"""Add notifications table

Revision ID: f1c290243dc9
Revises: e752a41dc38e
Create Date: 2026-06-30 02:33:28.197333

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'f1c290243dc9'
down_revision = 'e752a41dc38e'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('notifications',
    sa.Column('user_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=False),
    sa.Column('notification_type', sa.Enum('message', 'offer', 'offer_accepted', 'offer_rejected', 'meetup', 'favorite', 'listing', 'premium', 'advertisement', 'report', 'system', name='notification_type'), nullable=False),
    sa.Column('title', sa.String(length=150), nullable=False),
    sa.Column('message', sa.String(length=500), nullable=False),
    sa.Column('related_entity_type', sa.Enum('listing', 'offer', 'conversation', 'message', 'meetup', 'report', 'advertisement', 'subscription', 'system', name='related_entity_type'), nullable=True),
    sa.Column('related_entity_id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), nullable=True),
    sa.Column('read_at', sa.DateTime(), nullable=True),
    sa.Column('expires_at', sa.DateTime(), nullable=True),
    sa.Column('id', sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), autoincrement=True, nullable=False),
    sa.Column('public_id', sa.CHAR(length=36), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('public_id')
    )
    with op.batch_alter_table('notifications', schema=None) as batch_op:
        batch_op.create_index('ix_notifications_created_at', ['created_at'], unique=False)
        batch_op.create_index(batch_op.f('ix_notifications_expires_at'), ['expires_at'], unique=False)
        batch_op.create_index(batch_op.f('ix_notifications_notification_type'), ['notification_type'], unique=False)
        batch_op.create_index(batch_op.f('ix_notifications_read_at'), ['read_at'], unique=False)
        batch_op.create_index(batch_op.f('ix_notifications_related_entity_id'), ['related_entity_id'], unique=False)
        batch_op.create_index(batch_op.f('ix_notifications_related_entity_type'), ['related_entity_type'], unique=False)
        batch_op.create_index(batch_op.f('ix_notifications_user_id'), ['user_id'], unique=False)

    # ### end Alembic commands ###


def downgrade():
    # Dropping the table removes its indexes and foreign key together.
    # (On MySQL, dropping an FK-backing index first fails with errno 1553.)
    op.drop_table('notifications')
