"""Simple OpenAI file upload / delete helpers."""
from __future__ import annotations

from openai import OpenAI

from crystallise.llm.retry import call_with_retries


def upload_file(
    client: OpenAI,
    file_bytes: bytes,
    filename: str,
    purpose: str = "assistants",
) -> str:
    """Upload a file to OpenAI and return its file ID."""
    uploaded = call_with_retries(
        client.files.create,
        file=(filename, file_bytes),
        purpose=purpose,
    )
    return uploaded.id


def delete_file(client: OpenAI, file_id: str) -> None:
    """Delete a file from OpenAI by its file ID."""
    call_with_retries(client.files.delete, file_id=file_id)
