import datetime
from enum import Enum

import dateparser
import dateparser.date_parser


class Day(str, Enum):
    TODAY = "today"
    TOMORROW = "tomorrow"
    DAY_3 = "3-day"
    DAY_4 = "4-day"
    DAY_5 = "5-day"


def parse(value: str) -> datetime.date:
    if value in ["today", "mock"]:
        return datetime.date.today()
    elif value == "tomorrow":
        return datetime.date.today() + datetime.timedelta(days=1)
    elif value.endswith("-day"):
        days = int(value.split("-")[0]) - 1
        return datetime.date.today() + datetime.timedelta(days=days)
    else:
        date = dateparser.parse(value)
        if date is None:
            raise ValueError(value)
        return date.date()


def dump(date: datetime.date) -> str:
    today = datetime.date.today()
    days = (date - today).days
    if days == 0:
        return "today"
    elif days == 1:
        return "tomorrow"
    else:
        return f"{days + 1}-day"
