"""Schedule definitions for DAGs."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
from typing import Union


@dataclass(frozen=True)
class Cron:
    """Cron schedule expression."""
    expression: str

    def __str__(self) -> str:
        return self.expression


@dataclass(frozen=True)
class Interval:
    """Fixed interval schedule."""
    delta: timedelta

    def __str__(self) -> str:
        total = int(self.delta.total_seconds())
        if total % 86400 == 0:
            return f"every {total // 86400}d"
        if total % 3600 == 0:
            return f"every {total // 3600}h"
        if total % 60 == 0:
            return f"every {total // 60}m"
        return f"every {total}s"


Schedule = Union[Cron, Interval, None]
