"""add_guest_requests_table

Revision ID: guest_requests_001
Revises: inventory_management_001
Create Date: 2025-01-02 14:00:00.000000

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql


# revision identifiers, used by Alembic.
revision = 'guest_requests_001'
down_revision = 'inventory_management_001'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # Create guest_requests table
    op.create_table(
        'guest_requests',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('booking_id', sa.Integer(), nullable=False),
        sa.Column('room_id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('request_type', sa.Enum(
            'extra_towels', 'extra_pillows', 'room_cleaning', 'turndown_service',
            'amenities', 'maintenance', 'room_service', 'other',
            name='requesttype'
        ), nullable=False),
        sa.Column('status', sa.Enum(
            'pending', 'in_progress', 'fulfilled', 'cancelled',
            name='requeststatus'
        ), nullable=False, server_default='pending'),
        sa.Column('priority', sa.Enum(
            'low', 'normal', 'high', 'urgent',
            name='requestpriority'
        ), nullable=False, server_default='normal'),
        sa.Column('title', sa.String(255), nullable=False),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('assigned_to', sa.Integer(), nullable=True),
        sa.Column('fulfilled_by', sa.Integer(), nullable=True),
        sa.Column('requested_at', sa.DateTime(), nullable=False),
        sa.Column('started_at', sa.DateTime(), nullable=True),
        sa.Column('fulfilled_at', sa.DateTime(), nullable=True),
        sa.Column('guest_notes', sa.Text(), nullable=True),
        sa.Column('staff_notes', sa.Text(), nullable=True),
        sa.Column('response_time_minutes', sa.Integer(), nullable=True),
        sa.Column('fulfillment_time_minutes', sa.Integer(), nullable=True),
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.Column('updated_at', sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(['booking_id'], ['bookings.id'], ),
        sa.ForeignKeyConstraint(['room_id'], ['rooms.id'], ),
        sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
        sa.ForeignKeyConstraint(['assigned_to'], ['users.id'], ),
        sa.ForeignKeyConstraint(['fulfilled_by'], ['users.id'], ),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_guest_requests_id'), 'guest_requests', ['id'], unique=False)
    op.create_index(op.f('ix_guest_requests_booking_id'), 'guest_requests', ['booking_id'], unique=False)
    op.create_index(op.f('ix_guest_requests_room_id'), 'guest_requests', ['room_id'], unique=False)
    op.create_index(op.f('ix_guest_requests_requested_at'), 'guest_requests', ['requested_at'], unique=False)


def downgrade() -> None:
    op.drop_index(op.f('ix_guest_requests_requested_at'), table_name='guest_requests')
    op.drop_index(op.f('ix_guest_requests_room_id'), table_name='guest_requests')
    op.drop_index(op.f('ix_guest_requests_booking_id'), table_name='guest_requests')
    op.drop_index(op.f('ix_guest_requests_id'), table_name='guest_requests')
    op.drop_table('guest_requests')

