"""Seed default global render positions (Beauty, 3/4 Front, 3/4 Back).

Revision ID: 057
Revises: 056
"""
from alembic import op
import sqlalchemy as sa

revision = "057"
down_revision = "056"
branch_labels = None
depends_on = None

_DEFAULT_POSITIONS = [
    {"name": "Beauty", "rotation_x": 0.0, "rotation_y": 0.0, "rotation_z": 0.0, "is_default": True, "sort_order": 0},
    {"name": "3/4 Front", "rotation_x": -15.0, "rotation_y": 45.0, "rotation_z": 0.0, "is_default": False, "sort_order": 1},
    {"name": "3/4 Back", "rotation_x": -15.0, "rotation_y": -135.0, "rotation_z": 0.0, "is_default": False, "sort_order": 2},
]


def upgrade() -> None:
    conn = op.get_bind()
    for pos in _DEFAULT_POSITIONS:
        conn.execute(
            sa.text(
                "INSERT INTO global_render_positions (id, name, rotation_x, rotation_y, rotation_z, is_default, sort_order, created_at, updated_at) "
                "VALUES (gen_random_uuid(), :name, :rx, :ry, :rz, :is_default, :sort_order, now(), now())"
            ),
            {"name": pos["name"], "rx": pos["rotation_x"], "ry": pos["rotation_y"], "rz": pos["rotation_z"],
             "is_default": pos["is_default"], "sort_order": pos["sort_order"]},
        )


def downgrade() -> None:
    conn = op.get_bind()
    conn.execute(
        sa.text("DELETE FROM global_render_positions WHERE name IN ('Beauty', '3/4 Front', '3/4 Back')")
    )
