from __future__ import annotations

from typing import Annotated

from fastapi import APIRouter, Depends, Path

from v1.profile.dependencies import get_profile_service
from v1.profile.schemas import ProfileResponse, ProfileUpdateRequest
from v1.profile.service import ProfileService

router = APIRouter(prefix="/profile", tags=["profile"])


@router.get("/me", response_model=ProfileResponse)
async def get_me(
    service: Annotated[ProfileService, Depends(get_profile_service)],
) -> ProfileResponse:
    return await service.get_me()


@router.patch("/me", response_model=ProfileResponse)
async def update_me(
    payload: ProfileUpdateRequest,
    service: Annotated[ProfileService, Depends(get_profile_service)],
) -> ProfileResponse:
    return await service.update_me(payload)


@router.get("/{username}", response_model=ProfileResponse)
async def get_by_username(
    username: Annotated[
        str, Path(min_length=3, max_length=30, pattern="^[a-zA-Z0-9_]+$")
    ],
    service: Annotated[ProfileService, Depends(get_profile_service)],
) -> ProfileResponse:
    return await service.get_by_username(username)
