from __future__ import annotations

from typing import Annotated
from uuid import UUID

from fastapi import APIRouter, Depends, Query

from v1.inbox_messages.dependencies import get_inbox_message_service
from v1.inbox_messages.schemas import (
    InboxMessageAcceptRequest,
    InboxMessageListRequest,
    InboxMessageResponse,
    InboxMessageStatus,
)
from v1.inbox_messages.service import InboxMessageService

router = APIRouter(prefix="/inbox/messages", tags=["inbox-messages"])


@router.get("", response_model=list[InboxMessageResponse])
async def list_inbox_messages(
    service: Annotated[InboxMessageService, Depends(get_inbox_message_service)],
    status: InboxMessageStatus | None = Query(default=None),
) -> list[InboxMessageResponse]:
    request = InboxMessageListRequest(status=status)
    return await service.list_messages(request)


@router.post("/{message_id}/accept", response_model=InboxMessageResponse)
async def accept_inbox_message(
    message_id: UUID,
    request: InboxMessageAcceptRequest,
    service: Annotated[InboxMessageService, Depends(get_inbox_message_service)],
) -> InboxMessageResponse:
    return await service.accept_invitation(message_id, request)


@router.post("/{message_id}/dismiss", response_model=InboxMessageResponse)
async def dismiss_inbox_message(
    message_id: UUID,
    service: Annotated[InboxMessageService, Depends(get_inbox_message_service)],
) -> InboxMessageResponse:
    return await service.dismiss_invitation(message_id)
