import uuid
from pathlib import Path

from app.core.config import get_settings

settings = get_settings()


def save_upload(project_id: uuid.UUID, original_filename: str, content: bytes) -> tuple[str, str]:
    """Persist an uploaded file to disk. Returns (storage_path, stored_filename)."""
    project_dir = Path(settings.upload_dir) / str(project_id)
    project_dir.mkdir(parents=True, exist_ok=True)

    suffix = Path(original_filename).suffix
    stored_filename = f"{uuid.uuid4()}{suffix}"
    storage_path = project_dir / stored_filename
    storage_path.write_bytes(content)
    return str(storage_path), stored_filename
