"""Initial migration with all models

Revision ID: 050c22851c2d
Revises: 
Create Date: 2025-09-25 06:56:09.204691

"""
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = '050c22851c2d'
down_revision = None
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('users',
    sa.Column('uuid', sa.UUID(), nullable=True),
    sa.Column('email', sa.String(), nullable=False),
    sa.Column('phone', sa.String(), nullable=True),
    sa.Column('password_hash', sa.String(), nullable=False),
    sa.Column('first_name', sa.String(length=50), nullable=False),
    sa.Column('last_name', sa.String(length=50), nullable=False),
    sa.Column('date_of_birth', sa.Date(), nullable=True),
    sa.Column('avatar_url', sa.String(), nullable=True),
    sa.Column('bio', sa.Text(), nullable=True),
    sa.Column('emergency_contact_1_name', sa.String(length=100), nullable=True),
    sa.Column('emergency_contact_1_phone', sa.String(length=20), nullable=True),
    sa.Column('emergency_contact_2_name', sa.String(length=100), nullable=True),
    sa.Column('emergency_contact_2_phone', sa.String(length=20), nullable=True),
    sa.Column('location_sharing_enabled', sa.Boolean(), nullable=True),
    sa.Column('emergency_notifications_enabled', sa.Boolean(), nullable=True),
    sa.Column('push_notifications_enabled', sa.Boolean(), nullable=True),
    sa.Column('email_verified', sa.Boolean(), nullable=True),
    sa.Column('phone_verified', sa.Boolean(), nullable=True),
    sa.Column('is_blocked', sa.Boolean(), nullable=True),
    sa.Column('id', sa.Integer(), 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), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
    op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
    op.create_index(op.f('ix_users_phone'), 'users', ['phone'], unique=True)
    op.create_index(op.f('ix_users_uuid'), 'users', ['uuid'], unique=True)
    op.create_table('calendar_entries',
    sa.Column('uuid', sa.UUID(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('entry_date', sa.Date(), nullable=False),
    sa.Column('entry_type', sa.String(length=50), nullable=False),
    sa.Column('flow_intensity', sa.String(length=20), nullable=True),
    sa.Column('period_symptoms', sa.Text(), nullable=True),
    sa.Column('mood', sa.String(length=20), nullable=True),
    sa.Column('energy_level', sa.Integer(), nullable=True),
    sa.Column('sleep_hours', sa.Integer(), nullable=True),
    sa.Column('symptoms', sa.Text(), nullable=True),
    sa.Column('medications', sa.Text(), nullable=True),
    sa.Column('notes', sa.Text(), nullable=True),
    sa.Column('is_predicted', sa.Boolean(), nullable=True),
    sa.Column('confidence_score', sa.Integer(), nullable=True),
    sa.Column('id', sa.Integer(), 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), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_calendar_entries_entry_date'), 'calendar_entries', ['entry_date'], unique=False)
    op.create_index(op.f('ix_calendar_entries_id'), 'calendar_entries', ['id'], unique=False)
    op.create_index(op.f('ix_calendar_entries_user_id'), 'calendar_entries', ['user_id'], unique=False)
    op.create_index(op.f('ix_calendar_entries_uuid'), 'calendar_entries', ['uuid'], unique=True)
    op.create_table('cycle_data',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('cycle_start_date', sa.Date(), nullable=False),
    sa.Column('cycle_length', sa.Integer(), nullable=True),
    sa.Column('period_length', sa.Integer(), nullable=True),
    sa.Column('ovulation_date', sa.Date(), nullable=True),
    sa.Column('fertile_window_start', sa.Date(), nullable=True),
    sa.Column('fertile_window_end', sa.Date(), nullable=True),
    sa.Column('next_period_predicted', sa.Date(), nullable=True),
    sa.Column('cycle_regularity_score', sa.Integer(), nullable=True),
    sa.Column('avg_cycle_length', sa.Integer(), nullable=True),
    sa.Column('avg_period_length', sa.Integer(), nullable=True),
    sa.Column('id', sa.Integer(), 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), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_cycle_data_id'), 'cycle_data', ['id'], unique=False)
    op.create_index(op.f('ix_cycle_data_user_id'), 'cycle_data', ['user_id'], unique=False)
    op.create_table('emergency_alerts',
    sa.Column('uuid', sa.UUID(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('latitude', sa.Float(), nullable=False),
    sa.Column('longitude', sa.Float(), nullable=False),
    sa.Column('address', sa.String(length=500), nullable=True),
    sa.Column('alert_type', sa.String(length=50), nullable=True),
    sa.Column('message', sa.Text(), nullable=True),
    sa.Column('is_resolved', sa.Boolean(), nullable=True),
    sa.Column('resolved_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('resolved_by', sa.Integer(), nullable=True),
    sa.Column('notified_users_count', sa.Integer(), nullable=True),
    sa.Column('responded_users_count', sa.Integer(), nullable=True),
    sa.Column('id', sa.Integer(), 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), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['resolved_by'], ['users.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_emergency_alerts_id'), 'emergency_alerts', ['id'], unique=False)
    op.create_index(op.f('ix_emergency_alerts_user_id'), 'emergency_alerts', ['user_id'], unique=False)
    op.create_index(op.f('ix_emergency_alerts_uuid'), 'emergency_alerts', ['uuid'], unique=True)
    op.create_table('health_insights',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('insight_type', sa.String(length=50), nullable=False),
    sa.Column('title', sa.String(length=200), nullable=False),
    sa.Column('description', sa.Text(), nullable=False),
    sa.Column('recommendation', sa.Text(), nullable=True),
    sa.Column('confidence_level', sa.String(length=20), nullable=True),
    sa.Column('data_points_used', sa.Integer(), nullable=True),
    sa.Column('is_dismissed', sa.Boolean(), nullable=True),
    sa.Column('id', sa.Integer(), 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), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_health_insights_id'), 'health_insights', ['id'], unique=False)
    op.create_index(op.f('ix_health_insights_user_id'), 'health_insights', ['user_id'], unique=False)
    op.create_table('location_history',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('latitude', sa.Float(), nullable=False),
    sa.Column('longitude', sa.Float(), nullable=False),
    sa.Column('accuracy', sa.Float(), nullable=True),
    sa.Column('recorded_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('id', sa.Integer(), 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), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_history_coords_date', 'location_history', ['latitude', 'longitude', 'recorded_at'], unique=False)
    op.create_index('idx_history_user_date', 'location_history', ['user_id', 'recorded_at'], unique=False)
    op.create_index(op.f('ix_location_history_id'), 'location_history', ['id'], unique=False)
    op.create_index(op.f('ix_location_history_user_id'), 'location_history', ['user_id'], unique=False)
    op.create_table('user_locations',
    sa.Column('uuid', sa.UUID(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('latitude', sa.Float(), nullable=False),
    sa.Column('longitude', sa.Float(), nullable=False),
    sa.Column('accuracy', sa.Float(), nullable=True),
    sa.Column('altitude', sa.Float(), nullable=True),
    sa.Column('speed', sa.Float(), nullable=True),
    sa.Column('heading', sa.Float(), nullable=True),
    sa.Column('id', sa.Integer(), 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), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('idx_location_coords', 'user_locations', ['latitude', 'longitude'], unique=False)
    op.create_index('idx_location_user_time', 'user_locations', ['user_id', 'created_at'], unique=False)
    op.create_index(op.f('ix_user_locations_id'), 'user_locations', ['id'], unique=False)
    op.create_index(op.f('ix_user_locations_user_id'), 'user_locations', ['user_id'], unique=False)
    op.create_index(op.f('ix_user_locations_uuid'), 'user_locations', ['uuid'], unique=True)
    op.create_table('emergency_responses',
    sa.Column('alert_id', sa.Integer(), nullable=False),
    sa.Column('responder_id', sa.Integer(), nullable=False),
    sa.Column('response_type', sa.String(length=50), nullable=True),
    sa.Column('message', sa.Text(), nullable=True),
    sa.Column('eta_minutes', sa.Integer(), nullable=True),
    sa.Column('id', sa.Integer(), 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), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['alert_id'], ['emergency_alerts.id'], ),
    sa.ForeignKeyConstraint(['responder_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_emergency_responses_alert_id'), 'emergency_responses', ['alert_id'], unique=False)
    op.create_index(op.f('ix_emergency_responses_id'), 'emergency_responses', ['id'], unique=False)
    op.create_index(op.f('ix_emergency_responses_responder_id'), 'emergency_responses', ['responder_id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_emergency_responses_responder_id'), table_name='emergency_responses')
    op.drop_index(op.f('ix_emergency_responses_id'), table_name='emergency_responses')
    op.drop_index(op.f('ix_emergency_responses_alert_id'), table_name='emergency_responses')
    op.drop_table('emergency_responses')
    op.drop_index(op.f('ix_user_locations_uuid'), table_name='user_locations')
    op.drop_index(op.f('ix_user_locations_user_id'), table_name='user_locations')
    op.drop_index(op.f('ix_user_locations_id'), table_name='user_locations')
    op.drop_index('idx_location_user_time', table_name='user_locations')
    op.drop_index('idx_location_coords', table_name='user_locations')
    op.drop_table('user_locations')
    op.drop_index(op.f('ix_location_history_user_id'), table_name='location_history')
    op.drop_index(op.f('ix_location_history_id'), table_name='location_history')
    op.drop_index('idx_history_user_date', table_name='location_history')
    op.drop_index('idx_history_coords_date', table_name='location_history')
    op.drop_table('location_history')
    op.drop_index(op.f('ix_health_insights_user_id'), table_name='health_insights')
    op.drop_index(op.f('ix_health_insights_id'), table_name='health_insights')
    op.drop_table('health_insights')
    op.drop_index(op.f('ix_emergency_alerts_uuid'), table_name='emergency_alerts')
    op.drop_index(op.f('ix_emergency_alerts_user_id'), table_name='emergency_alerts')
    op.drop_index(op.f('ix_emergency_alerts_id'), table_name='emergency_alerts')
    op.drop_table('emergency_alerts')
    op.drop_index(op.f('ix_cycle_data_user_id'), table_name='cycle_data')
    op.drop_index(op.f('ix_cycle_data_id'), table_name='cycle_data')
    op.drop_table('cycle_data')
    op.drop_index(op.f('ix_calendar_entries_uuid'), table_name='calendar_entries')
    op.drop_index(op.f('ix_calendar_entries_user_id'), table_name='calendar_entries')
    op.drop_index(op.f('ix_calendar_entries_id'), table_name='calendar_entries')
    op.drop_index(op.f('ix_calendar_entries_entry_date'), table_name='calendar_entries')
    op.drop_table('calendar_entries')
    op.drop_index(op.f('ix_users_uuid'), table_name='users')
    op.drop_index(op.f('ix_users_phone'), table_name='users')
    op.drop_index(op.f('ix_users_id'), table_name='users')
    op.drop_index(op.f('ix_users_email'), table_name='users')
    op.drop_table('users')
    # ### end Alembic commands ###