"""
Asset data model for RedenLab ML SDK.

Represents an uploaded audio file that can be submitted to multiple models.
"""

from dataclasses import dataclass


@dataclass
class Asset:
    """
    Represents an uploaded audio file or chunk.

    An Asset is the result of uploading a file to S3. It can be submitted
    to any model without re-uploading. Assets are immutable once created.

    Attributes:
        asset_id: Unique identifier for this asset (generated by backend)
        filename: Original filename
        content_type: MIME type (e.g., 'audio/wav')
        duration: Audio duration in seconds (populated by backend Lambda after upload)
        parent_asset_id: Links chunks together (for chunked uploads)
        chunk_index: Order of this chunk within its parent (0-indexed)

    Example:
        >>> # Single file upload
        >>> asset = session.upload("audio.wav")
        >>> # Asset(asset_id="abc-123", filename="audio.wav", ...)

        >>> # Chunked upload
        >>> chunks = session.upload_chunked("long_audio.wav")
        >>> # [Asset(parent_asset_id="chunk_parent_xyz", chunk_index=0), ...]
    """

    asset_id: str
    filename: str
    content_type: str
    duration: float | None = None  # Populated by backend Lambda
    parent_asset_id: str | None = None  # Links chunks from same file
    chunk_index: int | None = None  # Order within parent (0-indexed)

    def is_chunk(self) -> bool:
        """Check if this asset is part of a chunked upload."""
        return self.parent_asset_id is not None

    def __repr__(self) -> str:
        """Return string representation of the asset."""
        if self.is_chunk():
            return (
                f"Asset(asset_id='{self.asset_id}', filename='{self.filename}', "
                f"chunk_index={self.chunk_index}, parent='{self.parent_asset_id}')"
            )
        return f"Asset(asset_id='{self.asset_id}', filename='{self.filename}')"
