# Path: craft_ai/errors.py
# class CraftAiError(Exception):
#     """Base class for exceptions in the craft ai client."""
# 
#     def __init__(self, message=None, metadata=None):
#         self.message = message
#         self.metadata = metadata
#         super(CraftAiError, self).__init__(message, metadata)
# 
#     def __str__(self):
#         return repr(self.message)
# 
# Path: craft_ai/operators.py
# OPERATORS = OPERATORS_V2
# 
# Path: craft_ai/types.py
# TYPES = {
#     "continuous": "continuous",
#     "enum": "enum",
#     "boolean": "boolean",
#     "timezone": "timezone",
#     "time_of_day": "time_of_day",
#     "day_of_week": "day_of_week",
#     "day_of_month": "day_of_month",
#     "month_of_year": "month_of_year",
# }
# 
# TYPE_ANY = "any"


import datetime
import math
from craft_ai.errors import CraftAiError
from craft_ai.operators import OPERATORS
from craft_ai.types import TYPES, TYPE_ANY


PROPERTY_FORMATTER = {
    TYPE_ANY: lambda value: value,
    TYPES["continuous"]: lambda number: "{:.2f}".format(number).rstrip("0").rstrip("."),
    TYPES["time_of_day"]: _time_formatter,
    TYPES["day_of_week"]: lambda day: DAYS[day.weekday()]
    if isinstance(day, datetime.datetime)
    else DAYS[day],
    TYPES["day_of_month"]: lambda day: day.day
    if isinstance(day, datetime.datetime)
    else day,
    # Months are in [1; 12] thus -1 to be index month name in [0; 11]
    TYPES["month_of_year"]: lambda month: MONTHS[month.month - 1]
    if isinstance(month, datetime.datetime)
    else MONTHS[month - 1],
}


def format_property(property_type, value=None):
    formatter = (
        PROPERTY_FORMATTER[property_type]
        if property_type in PROPERTY_FORMATTER
        else PROPERTY_FORMATTER[TYPE_ANY]
    )

    def extended_formatter(value):
        if value is None:
            return "null"
        if value == {}:

# Path: craft_ai/errors.py
# class CraftAiError(Exception):
#     """Base class for exceptions in the craft ai client."""
# 
#     def __init__(self, message=None, metadata=None):
#         self.message = message
#         self.metadata = metadata
#         super(CraftAiError, self).__init__(message, metadata)
# 
#     def __str__(self):
#         return repr(self.message)
# 
# Path: craft_ai/operators.py
# OPERATORS = OPERATORS_V2
# 
# Path: craft_ai/types.py
# TYPES = {
#     "continuous": "continuous",
#     "enum": "enum",
#     "boolean": "boolean",
#     "timezone": "timezone",
#     "time_of_day": "time_of_day",
#     "day_of_week": "day_of_week",
#     "day_of_month": "day_of_month",
#     "month_of_year": "month_of_year",
# }
# 
# TYPE_ANY = "any"


# Path: craft_ai/formatters.py
import datetime
import math
from craft_ai.errors import CraftAiError
from craft_ai.operators import OPERATORS
from craft_ai.types import TYPES, TYPE_ANY



PROPERTY_FORMATTER = {
    TYPE_ANY: lambda value: value,
    TYPES["continuous"]: lambda number: "{:.2f}".format(number).rstrip("0").rstrip("."),
    TYPES["time_of_day"]: _time_formatter,
    TYPES["day_of_week"]: lambda day: DAYS[day.weekday()]
    if isinstance(day, datetime.datetime)
    else DAYS[day],
    TYPES["day_of_month"]: lambda day: day.day
    if isinstance(day, datetime.datetime)
    else day,
    # Months are in [1; 12] thus -1 to be index month name in [0; 11]
    TYPES["month_of_year"]: lambda month: MONTHS[month.month - 1]
    if isinstance(month, datetime.datetime)
    else MONTHS[month - 1],
}


def format_property(property_type, value=None):
    formatter = (
        PROPERTY_FORMATTER[property_type]
        if property_type in PROPERTY_FORMATTER
        else PROPERTY_FORMATTER[TYPE_ANY]
    )

    def extended_formatter(value):
        if value is None:
            return "null"
        if value == {}:

            return "N/A"