import datetime
from enum import Enum
from typing import NamedTuple


class TagType(str, Enum):
    DAY = "day"
    DAYS = "days"


class Tag(NamedTuple):
    type: TagType
    date: datetime.date
    days: int = 1

    def __str__(self) -> str:
        if self.type == TagType.DAY:
            today = datetime.date.today()
            day = (self.date - today).days
            return f"day-{day}"
        elif self.type == TagType.DAYS:
            return f"days-{self.days}"
        else:
            raise ValueError(self.type)


class TagUtil:
    @classmethod
    def parse_tag(cls, tag: str) -> Tag:
        if tag == "today":
            return Tag(TagType.DAY, datetime.date.today())
        elif tag == "tomorrow":
            return Tag(TagType.DAY, datetime.date.today() + datetime.timedelta(days=1))
        elif tag.startswith("day-"):
            days = int(tag.split("-")[-1])
            return Tag(
                TagType.DAY,
                datetime.date.today() + datetime.timedelta(days=days),
            )
        elif tag.startswith("days-"):
            days = int(tag.split("-")[-1])
            return Tag(TagType.DAYS, datetime.date.today(), days)
        raise ValueError(tag)

    @classmethod
    def create_tag(
        cls,
        tag_type: TagType,
        date: datetime.date,
        day: int = 0,
        days: int = 10,
    ) -> Tag:
        if tag_type == TagType.DAY:
            return Tag(tag_type, date + datetime.timedelta(days=day))
        if tag_type == TagType.DAYS:
            return Tag(tag_type, date, days)
        raise ValueError(tag_type)
