from fastapi import APIRouter, Depends
from core.security.authentication import require_role, get_user
from schema import GenericResponse
from services.parent import ParentService
from services.participant import ParticipantService
from services.guest import GuestService

gdpr_router = APIRouter(prefix="/gdpr", tags=["GDPR"])


@gdpr_router.delete(
    "/parent/{parent_id}/erase",
    response_model=GenericResponse,
    dependencies=[Depends(require_role('admin'))]
)
async def erase_parent_data(
    parent_id: int,
    user=Depends(get_user),
    service: ParentService = Depends(ParentService)
):
    """GDPR: Erase Parent PII + all their child Participants. Payments retained."""
    result = service.erase_parent_personal_data(parent_id)
    return {"message": result["message"]}


@gdpr_router.delete(
    "/participant/{participant_id}/erase",
    response_model=GenericResponse,
    dependencies=[Depends(require_role('admin'))]
)
async def erase_participant_data(
    participant_id: int,
    user=Depends(get_user),
    service: ParticipantService = Depends(ParticipantService)
):
    """GDPR: Erase single Participant PII. Payments retained."""
    result = service.erase_participant_personal_data(participant_id)
    return {"message": result["message"]}


@gdpr_router.delete(
    "/guest/{guest_id}/erase",
    response_model=GenericResponse,
    dependencies=[Depends(require_role('admin'))]
)
async def erase_guest_data(
    guest_id: int,
    user=Depends(get_user),
    service: GuestService = Depends(GuestService)
):
    """GDPR: Erase Guest user PII."""
    result = service.erase_guest_personal_data(guest_id)
    return {"message": result["message"]}