"""APIهای احراز هویت OTP."""
from __future__ import annotations

from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession

from app.api.deps import get_db
from app.schemas.auth import (
    OtpRequestPayload,
    OtpRequestResponse,
    OtpVerifyPayload,
    TokenResponse,
)
from app.services.auth_service import AuthService

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


@router.post("/otp/request", response_model=OtpRequestResponse)
async def request_otp(
    payload: OtpRequestPayload,
    db: AsyncSession = Depends(get_db),
) -> OtpRequestResponse:
    return await AuthService(db).request_otp(payload.mobile, force_sms=payload.force_sms, context=payload.context)


@router.post("/otp/verify", response_model=TokenResponse)
async def verify_otp(
    payload: OtpVerifyPayload,
    db: AsyncSession = Depends(get_db),
) -> TokenResponse:
    return await AuthService(db).verify_otp(payload)
