"""add_coupons_and_promoter_role

Revision ID: 93054da1a687
Revises: ceda6a5abf0e
Create Date: 2026-01-28 10:41:47.113948

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


import sqlmodel


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


def upgrade() -> None:
    # Add 'promoter' to UserRole enum
    # Postgres specific command to add value to existing Enum
    with op.get_context().autocommit_block():
        op.execute("ALTER TYPE userrole ADD VALUE IF NOT EXISTS 'promoter'")

    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('coupons',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('title', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('discount_percentage', sa.Integer(), nullable=True),
    sa.Column('discount_amount', sa.Float(), nullable=True),
    sa.Column('category', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('valid_from', sa.DateTime(timezone=True), nullable=True),
    sa.Column('valid_until', sa.DateTime(timezone=True), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('coupons')
    # ### end Alembic commands ###
    # Note: Removing a value from a Postgres Enum is complex and usually not done in migrations
    # unless you recreate the whole type.

