import re
from datetime import date, datetime


def parse_date(value: str | date | datetime) -> str:
    """
    Parse a date value into a YYYY-MM-DD string.

    Accepts:
        - datetime objects
        - date objects
        - "YYYY-MM-DD" strings
        - "YYYY/MM/DD" strings

    Args:
        value: The date value to parse.

    Returns:
        A date string in YYYY-MM-DD format.

    Raises:
        TypeError: If value is not a str, date, or datetime.
        ValueError: If a string value doesn't match a recognized date format.
    """
    if isinstance(value, datetime):
        return value.strftime("%Y-%m-%d")
    if isinstance(value, date):
        return value.strftime("%Y-%m-%d")
    if isinstance(value, str):
        if re.match(r"^\d{4}-\d{2}-\d{2}$", value):
            return value
        if re.match(r"^\d{4}/\d{2}/\d{2}$", value):
            return datetime.strptime(value, "%Y/%m/%d").strftime("%Y-%m-%d")
        raise ValueError(
            f"Unrecognized date format: {value!r}. Expected YYYY-MM-DD or YYYY/MM/DD."
        )
    raise TypeError(f"Expected str, date, or datetime, got {type(value).__name__}")
