from typing import Annotated

from fastapi import APIRouter, Depends, Form

from core.security.authentication import get_user, require_role
from schema import GenericResponse
from schema.participant import AddParticipantSchema, ParticipantUpdateSchema, ParticipantProfileSchema
from services.participant import ParticipantService

participant_router = APIRouter(prefix="/participant")


@participant_router.post("/",dependencies=[Depends(require_role('parent'))], response_model=GenericResponse)
async def add_participant(request: AddParticipantSchema, user=Depends(get_user), service=Depends(ParticipantService)):
    service.add_participant(user, request)
    return {"message": "Participant added successfully."}


@participant_router.get("/" ,response_model=GenericResponse)
async def get_all_participant_by_current_user(user=Depends(get_user), service=Depends(ParticipantService),):
    data = service.fetch_current_participant(user)
    return {"message": "Participant populated successfully.", "data": data}


@participant_router.get("/{participant_id}", response_model=GenericResponse)
async def participant_details(participant_id: int, user=Depends(get_user), service=Depends(ParticipantService)):
    return {"message": "Participant populated successfully.", 'data': service.fetch_participant_details(participant_id)}


@participant_router.put("/{participant_id}", response_model=GenericResponse)
async def update_participant(participant_id: int, request: ParticipantUpdateSchema, user=Depends(get_user),
                             service=Depends(ParticipantService)):
    service.update_participant_from_parent(participant_id, request)
    return {"message": "Participant updated successfully."}


@participant_router.delete("/{participant_id}", response_model=GenericResponse)
async def delete_participant(participant_id: int, user=Depends(get_user), service=Depends(ParticipantService)):
    service.delete_participant(participant_id)
    return {"message": "Participant deleted successfully."}


@participant_router.get("/parent/{parent_id}" ,response_model=GenericResponse)
async def get_all_participant_by_parent_id(parent_id:int,user=Depends(get_user), service=Depends(ParticipantService),):
    data = service.get_all_participant_by_parent_id(parent_id)
    return {"message": "Participant populated successfully.", "data": data}