from typing import ClassVar, Dict, List, Tuple  # noqa: F401

from pydantic import Field, StrictStr
from typing import Any, Optional
from typing_extensions import Annotated
from openapi_server.models.create_customer_request import CreateCustomerRequest
from openapi_server.models.customer import Customer
from openapi_server.models.restaurant import Restaurant
from openapi_server.models.menu_item import MenuItem
from openapi_server.models.order_item import OrderItem
from openapi_server.models.update_customer_request import UpdateCustomerRequest
from openapi_server.models.restaurants_get200_response import RestaurantsGet200Response
from openapi_server.models.restaurants_id_orders_get200_response import RestaurantsIdOrdersGet200Response
from openapi_server.security_api import get_token_BasicAuth
from openapi_server.apis.customers_api_base import BaseCustomersApi
from openapi_server.apis.restaurants_api_base import BaseRestaurantsApi
from openapi_server.apis.orders_api_base import BaseOrdersApi

from fastapi import (  # noqa: F401
    HTTPException,
)

customers: List[Customer] = [
    Customer(id="1", name="Max Mustermann", email="max.mustermann@hallo-welt.de"),
    Customer(id="2", name="Nikolas Neuer", email="niklas.neuer@mail-provider.com")
]

restaurants: List[Restaurant] = [
    Restaurant(id="1", name="Peter Chan Chinese Take Away", address="30 Roods, Kirriemuir, Scotland, United Kingdom"),
    Restaurant(id="2", name="Pita Pan in Groß-Gerau", address="Mainzer Straße 10, Groß-Gerau, DE 64521"),
    Restaurant(id="3", name="Naansense Indian Inspired Eats", address="178 N Franklin St, Chicago, IL 60606"),
    Restaurant(id="4", name="Thai Tanic in Plainville", address="1 Man-Mar Dr, Ste 7, Plainville, MA 02762"),
    Restaurant(id="5", name="Grill Of Thrones in Þingholt", address="Address Lækjargata, 101 Reykjavík, Iceland"),
    Restaurant(id="6", name="Juan in a Million in Austin", address="2300 E Cesar Chavez St, Austin, TX 78702-4604"),
]

menues = {
    "1": [
        MenuItem(id="1", name="Hähnchen süßsauer", price=14.5),
        MenuItem(id="2", name="Teigtaschen", price=7.5),
        MenuItem(id="3", name="Pekingente", price=13.5),
        MenuItem(id="4", name="Gebratene Nudeln", price=11)
    ],
    "2": [
        MenuItem(id="1", name="Maultaschen", price=12),
        MenuItem(id="2", name="Zwiebelkuchen", price=12.5),
        MenuItem(id="3", name="Rösti", price=11),
    ],
    "3": [
        MenuItem(id="1", name="Frühlingsrollen", price=5.5),
        MenuItem(id="2", name="Reis", price=8.5),
        MenuItem(id="3", name="Curry", price=12)
    ],
    "4": [
        MenuItem(id="1", name="Pizza Marinara", price=12),
        MenuItem(id="2", name="Pizza Magherita", price=10.5),
        MenuItem(id="3", name="Pizza Salami", price=10.5)
    ],
    "5": [
        MenuItem(id="1", name="Gegrilltes Hähnchen", price=8.5),
        MenuItem(id="2", name="BBQ", price=9.5),
        MenuItem(id="3", name="Burger", price=13.5)
    ],
    "6": [
        MenuItem(id="1", name="Tacos", price=10),
        MenuItem(id="2", name="Chili", price=12.5),
        MenuItem(id="3", name="Tortillas", price=15),
    ]
}

orders = {
    "1": [
        OrderItem(menuItemId="1", quantity=2),
        OrderItem(menuItemId="2", quantity=2)
    ],
    "2": [
        OrderItem(menuItemId="1", quantity=1),
        OrderItem(menuItemId="2", quantity=1)
    ],
    "3": [
        OrderItem(menuItemId="1", quantity=1),
        OrderItem(menuItemId="2", quantity=1)
    ],
    "4": [
        OrderItem(menuItemId="1", quantity=1),
        OrderItem(menuItemId="2", quantity=1)
    ],
    "5": [
        OrderItem(menuItemId="1", quantity=1),
        OrderItem(menuItemId="2", quantity=1)
    ],
    "6": [
        OrderItem(menuItemId="1", quantity=1),
        OrderItem(menuItemId="2", quantity=1)
    ]
}

class MyCustomersApi(BaseCustomersApi):
    async def customers_post(
        self,
        create_customer_request: CreateCustomerRequest,
        idempotency_key: Annotated[Optional[StrictStr], Field(description="Unique key to prevent duplicate orders")],
    ) -> Customer:
        if create_customer_request is None:
            raise HTTPException(status_code=404, detail="Customer not found")
        customer: Customer = Customer(id=idempotency_key, name=create_customer_request.name, email=create_customer_request.email)
        customers.append(customer)
        raise HTTPException(status_code=201, detail="Customer created")
        return customer


    async def customers_me_get(
        self,
    ) -> Customer:
        """Returns the authenticated customer&#39;s profile"""
        return Customer(id="1", name="Max Mustermann", email="max.mustermann@hallo-welt.de")


    async def customers_id_get(
        self,
        id: StrictStr,
    ) -> Customer:
        customer: Customer = next(filter(lambda c: c.id == id, customers), None)
        if customer is None:
            raise HTTPException(status_code=404, detail="Customer not found")
        return customer


    async def customers_id_delete(
        self,
        id: StrictStr,
    ) -> None:
        customer: Customer = next(filter(lambda c: c.id == id, customers), None)
        if customer is None:
            raise HTTPException(status_code=404, detail="Customer not found")
        customers.remove(customer)

        raise HTTPException(status_code=204, detail="Customer updated")
        return None


    async def customers_id_patch(
        self,
        id: StrictStr,
        update_customer_request: UpdateCustomerRequest,
    ) -> Customer:
        if update_customer_request is None:
            raise HTTPException(status_code=404, detail="Customer not found")
        customer: Customer = next(filter(lambda c: c.id == id, customers), None)
        if customer is None:
            raise HTTPException(status_code=404, detail="Customer not found")
        customers.remove(customer)
        customers.append(Customer(id=id, name=update_customer_request.name, email=update_customer_request.email))
        raise HTTPException(status_code=201, detail="Customer updated")
        return customer        

class MyRestaurantsApi(BaseRestaurantsApi):
    subclasses: ClassVar[Tuple] = ()

    def __init_subclass__(cls, **kwargs):
        super().__init_subclass__(**kwargs)
        BaseRestaurantsApi.subclasses = BaseRestaurantsApi.subclasses + (cls,)
    async def restaurants_get(
        self,
        limit: Optional[Annotated[int, Field(le=100, strict=True, ge=1)]],
        offset: Optional[Annotated[int, Field(strict=True, ge=0)]],
        accept_language: Annotated[Optional[StrictStr], Field(description="Preferred language for localized strings.")],
    ) -> RestaurantsGet200Response:
        response: RestaurantsGet200Response = RestaurantsGet200Response(data=restaurants)
        return response
        


    async def restaurants_id_menu_get(
        self,
        id: StrictStr,
        accept_language: Annotated[Optional[StrictStr], Field(description="Preferred language for localized strings.")],
    ) -> List[MenuItem]:
        if id in menues:
            return menues[id]
        raise HTTPException(status_code=404, detail="Restaurant not found")


    async def restaurants_id_orders_get(
        self,
        id: StrictStr,
        limit: Optional[Annotated[int, Field(le=100, strict=True, ge=1)]],
        offset: Optional[Annotated[int, Field(strict=True, ge=0)]],
    ) -> RestaurantsIdOrdersGet200Response:
        print(orders[id])
        if id in orders:
            return RestaurantsIdOrdersGet200Response(data=orders[id])
        raise HTTPException(status_code=404, detail="Restaurant not found")

class MyOrdersAPI(BaseOrdersApi):
    subclasses: ClassVar[Tuple] = ()

    def __init_subclass__(cls, **kwargs):
        super().__init_subclass__(**kwargs)
        BaseOrdersApi.subclasses = BaseOrdersApi.subclasses + (cls,)
    async def restaurants_id_orders_get(
        self,
        id: StrictStr,
        limit: Optional[Annotated[int, Field(le=100, strict=True, ge=1)]],
        offset: Optional[Annotated[int, Field(strict=True, ge=0)]],
    ) -> RestaurantsIdOrdersGet200Response:
        """Retrieve a paginated list of orders for a specific restaurant."""
        if id in orders:
            return RestaurantsIdOrdersGet200Response(data=orders[id])
        raise HTTPException(status_code=404, detail="Restaurant not found")


    async def orders_post(
        self,
        create_order_request: CreateOrderRequest,
        idempotency_key: Annotated[Optional[StrictStr], Field(description="Unique key to prevent duplicate orders")],
    ) -> Order:
        ...


    async def orders_order_id_get(
        self,
        orderId: StrictStr,
    ) -> Order:
        ...


    async def orders_order_id_status_patch(
        self,
        orderId: StrictStr,
        update_order_status_request: UpdateOrderStatusRequest,
    ) -> Order:
        """Update the status of an existing order."""
        ...