"""Attachment Pydantic schemas."""

from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel, Field, computed_field


class AttachmentResponse(BaseModel):
    """Single task attachment."""

    id: int
    task_id: int
    project_id: str
    filename: str
    content_type: str
    size_bytes: int
    s3_key: str = Field(exclude=True)
    download_url: str
    uploaded_by_user_id: int | None
    created_at: datetime

    @computed_field  # type: ignore[misc]
    @property
    def is_image(self) -> bool:
        return self.content_type.startswith("image/")
