"""Task log database model."""
from __future__ import annotations

from datetime import datetime

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

from crondag.models.base import Base


class TaskLogModel(Base):
    __tablename__ = "task_log"

    id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
    task_instance_id: Mapped[int] = mapped_column(Integer, ForeignKey("task_instance.id"), index=True)
    line_number: Mapped[int] = mapped_column(Integer)
    timestamp: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
    level: Mapped[str] = mapped_column(String(10), default="INFO")
    message: Mapped[str] = mapped_column(Text, default="")

    def __repr__(self) -> str:
        return f"<TaskLogModel ti_id={self.task_instance_id} line={self.line_number}>"
