"""Add user deck building tables

Revision ID: 002
Revises: 001
Create Date: 2026-01-02 00:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


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


def upgrade() -> None:
    """Create user decks table (deck building tables moved to 003)."""
    
    # 1. User Decks Table
    op.create_table(
        'user_decks',
        sa.Column('id', sa.BigInteger().with_variant(sa.Integer, "sqlite"), primary_key=True, autoincrement=True),
        sa.Column('user_id', sa.Integer(), sa.ForeignKey('mtgonline_users.id', ondelete='CASCADE'), nullable=False, index=True),
        sa.Column('name', sa.String(255), nullable=False, index=True),
        sa.Column('status', sa.String(20), nullable=False, default='DRAFT', index=True),
        sa.Column('folder_id', sa.Integer(), sa.ForeignKey('mtgonline_decklist_folders.id'), nullable=True),
        sa.Column('format', sa.String(50), nullable=True, default='standard'),
        sa.Column('notes', sa.Text(), nullable=True),
        sa.Column('is_precedent', sa.Boolean(), default=False, index=True),
        sa.Column('precedent_name', sa.String(255), nullable=True),
        sa.Column('created_at', sa.DateTime(), server_default=sa.func.now()),
        sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now(), onupdate=sa.func.now()),
    )


def downgrade() -> None:
    """Drop user decks table."""
    op.drop_table('user_decks')
