"""Account app action endpoints.

All actions remain as Python fallbacks (local service imports).
"""
from __future__ import annotations

from quart import Blueprint, g, request

from shared.infrastructure.query_blueprint import create_action_blueprint


def register() -> Blueprint:
    bp, _handlers = create_action_blueprint("account")

    async def _ghost_sync_member():
        data = await request.get_json()
        ghost_id = data.get("ghost_id")
        if not ghost_id:
            return {"error": "ghost_id required"}, 400
        from services.ghost_membership import sync_single_member
        await sync_single_member(g.s, ghost_id)
        return {"ok": True}

    _handlers["ghost-sync-member"] = _ghost_sync_member

    async def _ghost_push_member():
        data = await request.get_json()
        user_id = data.get("user_id")
        if not user_id:
            return {"error": "user_id required"}, 400
        from services.ghost_membership import sync_member_to_ghost
        result_id = await sync_member_to_ghost(g.s, int(user_id))
        return {"ok": True, "ghost_id": result_id}

    _handlers["ghost-push-member"] = _ghost_push_member

    return bp
