"""SQLAlchemy model for health check snapshots."""

import uuid
from datetime import datetime

from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text, Uuid, func
from sqlalchemy.orm import Mapped, mapped_column

from src.models.base import Base, UUIDPrimaryKeyMixin


class HealthCheck(UUIDPrimaryKeyMixin, Base):
    __tablename__ = "health_checks"

    instance_id: Mapped[uuid.UUID] = mapped_column(
        Uuid(as_uuid=True),
        ForeignKey("tool_instances.id", ondelete="CASCADE"),
        nullable=False,
    )
    container_status: Mapped[str | None] = mapped_column(String(50), nullable=True)
    container_healthy: Mapped[bool | None] = mapped_column(Boolean, nullable=True)
    tunnel_healthy: Mapped[bool | None] = mapped_column(Boolean, nullable=True)
    exit_code: Mapped[int | None] = mapped_column(Integer, nullable=True)
    probe_status: Mapped[str | None] = mapped_column(String(50), nullable=True)
    probe_output: Mapped[str | None] = mapped_column(Text, nullable=True)
    checked_at: Mapped[datetime] = mapped_column(
        DateTime(timezone=True),
        server_default=func.now(),
        nullable=False,
    )
