"""DAG database model."""
from __future__ import annotations

from datetime import datetime

from sqlalchemy import Boolean, DateTime, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from crondag.models.base import Base


class DagModel(Base):
    __tablename__ = "dag"

    dag_id: Mapped[str] = mapped_column(String(250), primary_key=True)
    description: Mapped[str] = mapped_column(Text, default="")
    schedule_type: Mapped[str | None] = mapped_column(String(50), nullable=True)  # "cron", "interval", null
    schedule_value: Mapped[str | None] = mapped_column(String(250), nullable=True)
    schedule_timezone: Mapped[str] = mapped_column(String(50), default="UTC")
    is_paused: Mapped[bool] = mapped_column(Boolean, default=False)
    fileloc: Mapped[str] = mapped_column(String(500), default="")
    next_run_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
    last_parsed_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
    tags: Mapped[str] = mapped_column(Text, default="")  # JSON array as string

    def __repr__(self) -> str:
        return f"<DagModel dag_id={self.dag_id!r}>"
