"""image url chat

Revision ID: ea9af0313019
Revises: 6a790c90ae30
Create Date: 2025-09-05 10:42:39.581336

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

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


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('idx_store_performance_scores_branch_id', table_name='store_performance_scores')
    op.drop_index('idx_store_performance_scores_month_year', table_name='store_performance_scores')
    op.drop_index('idx_store_performance_scores_store_branch_month', table_name='store_performance_scores')
    op.drop_index('idx_store_performance_scores_store_id', table_name='store_performance_scores')
    op.drop_index('idx_store_performance_scores_unique', table_name='store_performance_scores', postgresql_where='(is_active = true)')
    op.drop_table('store_performance_scores')
    op.add_column('chat_messages', sa.Column('image_url', sa.String(length=500), nullable=True))
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('chat_messages', 'image_url')
    op.create_table('store_performance_scores',
    sa.Column('id', sa.BIGINT(), autoincrement=True, nullable=False),
    sa.Column('store_id', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('branch_id', sa.BIGINT(), autoincrement=False, nullable=True),
    sa.Column('overall_score', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=False),
    sa.Column('engagement_rate', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=False),
    sa.Column('reach_efficiency', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=False),
    sa.Column('posting_consistency', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=False),
    sa.Column('platform_scores', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('total_posts', sa.INTEGER(), server_default=sa.text('0'), autoincrement=False, nullable=True),
    sa.Column('total_engagement', sa.BIGINT(), server_default=sa.text('0'), autoincrement=False, nullable=True),
    sa.Column('total_impressions', sa.BIGINT(), server_default=sa.text('0'), autoincrement=False, nullable=True),
    sa.Column('total_followers', sa.BIGINT(), server_default=sa.text('0'), autoincrement=False, nullable=True),
    sa.Column('connected_accounts_count', sa.INTEGER(), server_default=sa.text('0'), autoincrement=False, nullable=True),
    sa.Column('score_month', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('score_year', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
    sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
    sa.Column('is_active', sa.BOOLEAN(), server_default=sa.text('true'), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name='store_performance_scores_pkey')
    )
    op.create_index('idx_store_performance_scores_unique', 'store_performance_scores', ['store_id', sa.text('COALESCE(branch_id, 0::bigint)'), 'score_year', 'score_month'], unique=True, postgresql_where='(is_active = true)')
    op.create_index('idx_store_performance_scores_store_id', 'store_performance_scores', ['store_id'], unique=False)
    op.create_index('idx_store_performance_scores_store_branch_month', 'store_performance_scores', ['store_id', 'branch_id', 'score_year', 'score_month'], unique=False)
    op.create_index('idx_store_performance_scores_month_year', 'store_performance_scores', ['score_year', 'score_month'], unique=False)
    op.create_index('idx_store_performance_scores_branch_id', 'store_performance_scores', ['branch_id'], unique=False)
    # ### end Alembic commands ###
