from dataclasses import dataclass
from datetime import datetime
from decimal import Decimal
from enum import StrEnum
from typing import Optional, Iterable, Self

from src.ezgg_lan_manager.types.CateringMenuItem import CateringMenuItem, CateringMenuItemCategory
from src.ezgg_lan_manager.types.User import User

CateringMenuItemsWithAmount = dict[CateringMenuItem, int]


class CateringOrderStatus(StrEnum):
    RECEIVED = "RECEIVED"
    DELAYED = "DELAYED"
    READY_FOR_PICKUP = "READY_FOR_PICKUP"
    EN_ROUTE = "EN_ROUTE"
    COMPLETED = "COMPLETED"
    CANCELED = "CANCELED"


@dataclass(frozen=True)
class CateringOrder:
    order_id: int
    order_date: datetime
    status: CateringOrderStatus
    items: CateringMenuItemsWithAmount
    customer: User
    is_delivery: bool = True

    @property
    def price(self) -> Decimal:
        total = Decimal("0")
        for item, amount in self.items.items():
            total += (item.price * amount)
        return total

    @staticmethod
    def translate_order_status(status: CateringOrderStatus) -> str:
        if status == CateringOrderStatus.RECEIVED:
            return "Eingegangen"
        elif status == CateringOrderStatus.DELAYED:
            return "Verzögert"
        elif status == CateringOrderStatus.READY_FOR_PICKUP:
            return "Abholbereit"
        elif status == CateringOrderStatus.EN_ROUTE:
            return "In Zustellung"
        elif status == CateringOrderStatus.COMPLETED:
            return "Abgeschlossen"
        elif status == CateringOrderStatus.CANCELED:
            return "Storniert"
        else:
            raise RuntimeError("Unknown CateringOrderStatus:", status)
