"""Add admin-managed contextual prompt suggestions."""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

revision = "182"
down_revision = "181"
branch_labels = None
depends_on = None

def upgrade() -> None:
    op.create_table(
        "prompt_suggestions",
        sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
        sa.Column("name", sa.String(120), nullable=False),
        sa.Column("prompt", sa.Text(), nullable=False),
        sa.Column("matching_keywords", postgresql.JSONB(), nullable=False, server_default="[]"),
        sa.Column("excluded_keywords", postgresql.JSONB(), nullable=False, server_default="[]"),
        sa.Column("required_keywords", postgresql.JSONB(), nullable=False, server_default="[]"),
        sa.Column("project_types", postgresql.JSONB(), nullable=False, server_default="[]"),
        sa.Column("priority", sa.Integer(), nullable=False, server_default="100"),
        sa.Column("is_fallback", sa.Boolean(), nullable=False, server_default=sa.false()),
        sa.Column("is_active", sa.Boolean(), nullable=False, server_default=sa.true()),
        sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
        sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
    )
    op.execute(sa.text("""
      INSERT INTO prompt_suggestions
        (id, name, prompt, matching_keywords, excluded_keywords, required_keywords, project_types, priority, is_fallback)
      VALUES
        (gen_random_uuid(), 'Legal firm website', 'Build a professional website for {project_name} with legal services, attorney profiles, consultation requests, and a contact form', '["law", "legal", "lawyer", "attorney", "firm", "solicitor", "counsel", "advocate"]', '[]', '[]', '[]', 10, false),
        (gen_random_uuid(), 'Restaurant website', 'Build a website for {project_name} with a menu, opening hours, location, and reservation form', '["restaurant", "cafe", "coffee", "food", "bakery", "bar", "diner"]', '[]', '[]', '[]', 10, false),
        (gen_random_uuid(), 'Healthcare website', 'Build a website for {project_name} with services, providers, opening hours, and appointment booking', '["clinic", "medical", "doctor", "dental", "dentist", "health", "therapy"]', '[]', '[]', '[]', 10, false),
        (gen_random_uuid(), 'Neutral business website', 'Build a professional website for {project_name} with a clear homepage, services, about section, and contact form', '[]', '[]', '[]', '[]', 1000, true),
        (gen_random_uuid(), 'Neutral customer web app', 'Create a modern customer-facing web app for {project_name} with user accounts, a dashboard, and its core customer workflow', '[]', '[]', '[]', '[]', 1001, true)
    """))

def downgrade() -> None:
    op.drop_table("prompt_suggestions")
