"""cms_pages: drop SEO columns; seed 4 legal pages

Revision ID: 0030
Revises: 0029
Create Date: 2026-06-29
"""
from alembic import op
import sqlalchemy as sa

revision = "0030"
down_revision = "0029"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.drop_column("cms_pages", "seo_title")
    op.drop_column("cms_pages", "seo_description")

    op.execute("UPDATE cms_pages SET headline = name WHERE headline IS NULL OR headline = ''")
    op.execute("UPDATE cms_pages SET subhead = '' WHERE subhead IS NULL")

    op.alter_column("cms_pages", "headline", nullable=False)
    op.alter_column("cms_pages", "subhead", nullable=False)

    op.execute("""
        INSERT INTO cms_pages (id, name, path, headline, subhead, status, created_at, updated_at)
        VALUES
          (gen_random_uuid(), 'Privacy', 'privacy',
           'Your privacy is at the heart of everything we do.',
           'We handle your data with the same dignity we expect cemeteries to show every family.',
           'Published', now(), now()),
          (gen_random_uuid(), 'Terms', 'terms',
           'Clear terms for a trusted partnership.',
           'Straightforward terms of service designed to protect you, your data, and the families you serve.',
           'Published', now(), now()),
          (gen_random_uuid(), 'PIPEDA', 'pipeda',
           'How we handle your data under Canadian privacy law.',
           'INDELIS is fully compliant with the Personal Information Protection and Electronic Documents Act.',
           'Published', now(), now()),
          (gen_random_uuid(), 'Accessibility', 'accessibility',
           'Built for everyone.',
           'INDELIS is committed to making cemetery management software accessible to all users, regardless of ability.',
           'Published', now(), now())
        ON CONFLICT (path) DO NOTHING
    """)


def downgrade() -> None:
    op.add_column("cms_pages", sa.Column("seo_title", sa.String(255), nullable=True))
    op.add_column("cms_pages", sa.Column("seo_description", sa.Text, nullable=True))
    op.alter_column("cms_pages", "headline", nullable=True)
    op.alter_column("cms_pages", "subhead", nullable=True)
    op.execute("DELETE FROM cms_pages WHERE path IN ('privacy', 'terms', 'pipeda', 'accessibility')")
