"""add venue canon and preferences

Revision ID: bc26bfdca841
Revises: 81e183e75ff5
Create Date: 2025-12-29 12:57:55.838639

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
import sqlmodel


# revision identifiers, used by Alembic.
revision: str = 'bc26bfdca841'
down_revision: Union[str, Sequence[str], None] = '4f14be7d0551'
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('venuecanon',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('city', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('state', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('country', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('latitude', sa.Float(), nullable=True),
    sa.Column('longitude', sa.Float(), nullable=True),
    sa.Column('capacity', sa.Integer(), nullable=True),
    sa.Column('website_url', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('venuecanon', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_venuecanon_name'), ['name'], unique=False)
        batch_op.create_index(batch_op.f('ix_venuecanon_slug'), ['slug'], unique=True)

    op.create_table('userplaylist',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('is_public', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('userplaylist', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_userplaylist_name'), ['name'], unique=False)
        batch_op.create_index(batch_op.f('ix_userplaylist_slug'), ['slug'], unique=False)

    op.create_table('festival',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('year', sa.Integer(), nullable=True),
    sa.Column('start_date', sa.DateTime(), nullable=True),
    sa.Column('end_date', sa.DateTime(), nullable=True),
    sa.Column('venue_id', sa.Integer(), nullable=True),
    sa.Column('website_url', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.ForeignKeyConstraint(['venue_id'], ['venue.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('festival', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_festival_name'), ['name'], unique=False)
        batch_op.create_index(batch_op.f('ix_festival_slug'), ['slug'], unique=True)

    op.create_table('showfestival',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('show_id', sa.Integer(), nullable=False),
    sa.Column('festival_id', sa.Integer(), nullable=False),
    sa.Column('stage', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('set_time', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.ForeignKeyConstraint(['festival_id'], ['festival.id'], ),
    sa.ForeignKeyConstraint(['show_id'], ['show.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('playlistperformance',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('playlist_id', sa.Integer(), nullable=False),
    sa.Column('performance_id', sa.Integer(), nullable=False),
    sa.Column('position', sa.Integer(), nullable=False),
    sa.Column('added_at', sa.DateTime(), nullable=False),
    sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.ForeignKeyConstraint(['performance_id'], ['performance.id'], ),
    sa.ForeignKeyConstraint(['playlist_id'], ['userplaylist.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    # with op.batch_alter_table('userverticalpreference', schema=None) as batch_op:
    #     batch_op.add_column(sa.Column('tier', sa.Enum('HEADLINER', 'MAIN_STAGE', 'SUPPORTING', name='preferencetier'), nullable=False))

    with op.batch_alter_table('venue', schema=None) as batch_op:
        batch_op.add_column(sa.Column('canon_id', sa.Integer(), nullable=True))
        batch_op.create_foreign_key('fk_venue_canon_id_venuecanon', 'venuecanon', ['canon_id'], ['id'])

    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('venue', schema=None) as batch_op:
        batch_op.drop_constraint(None, type_='foreignkey')
        batch_op.drop_column('canon_id')

    with op.batch_alter_table('userverticalpreference', schema=None) as batch_op:
        batch_op.drop_column('tier')

    op.drop_table('playlistperformance')
    op.drop_table('showfestival')
    with op.batch_alter_table('festival', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_festival_slug'))
        batch_op.drop_index(batch_op.f('ix_festival_name'))

    op.drop_table('festival')
    with op.batch_alter_table('userplaylist', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_userplaylist_slug'))
        batch_op.drop_index(batch_op.f('ix_userplaylist_name'))

    op.drop_table('userplaylist')
    with op.batch_alter_table('venuecanon', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_venuecanon_slug'))
        batch_op.drop_index(batch_op.f('ix_venuecanon_name'))

    op.drop_table('venuecanon')
    # ### end Alembic commands ###
