from __future__ import annotations

from fastapi import APIRouter, Depends, File, UploadFile
from sqlalchemy.orm import Session

from app.core.database import get_db
from app.core.dependencies import get_current_user
from app.core.responses import api_success
from app.models.user import User
from app.services.voice_input_service import MAX_UPLOAD_BYTES, VoiceInputService

router = APIRouter()


@router.get("/config")
def voice_config(db: Session = Depends(get_db), _user: User = Depends(get_current_user)) -> dict:
    return api_success(VoiceInputService.public_config(db))


@router.post("/transcribe")
def transcribe(
    audio: UploadFile = File(...),
    db: Session = Depends(get_db),
    user: User = Depends(get_current_user),
) -> dict:
    content = audio.file.read(MAX_UPLOAD_BYTES + 1)
    return api_success(VoiceInputService.transcribe(db, user.id, content, audio.content_type))
