"""ImageEntry model for AXM Data Catalog (Plugin).

Moved from axm-core to axm-image.
"""

from typing import Literal

from pydantic import BaseModel, Field

from axm.catalog.entries.data import (
    DataEntry,
    Schema,
    SchemaFormat,
)


class ImageSpec(BaseModel):
    """Specific attributes for image data.

    Attributes:
        encoding: Image encoding format (e.g., "png", "jpeg").
        color_space: Color representation (default: "RGB").
        channels: Number of color channels (default: 3).
        width: Image width in pixels.
        height: Image height in pixels.
        compression: Optional compression method.
    """

    encoding: str
    color_space: str = "RGB"
    channels: int = 3
    width: int | None = Field(default=None, gt=0)
    height: int | None = Field(default=None, gt=0)
    compression: str | None = None


class ImageSchema(Schema):
    """Schema definition for image data.

    Matches the YAML structure where details are nested in 'spec'.
    """

    format: Literal[SchemaFormat.IMAGE] = SchemaFormat.IMAGE
    spec: ImageSpec


class ImageEntry(DataEntry):
    """A data catalog entry for image files.

    Specialized entry with typed schema for image metadata.
    """

    # Override schema with specialized ImageSchema
    data_schema: ImageSchema = Field(alias="schema")

    @property
    def format(self) -> str:
        """Return the data format identifier."""
        return "image"
