from typing import Optional

import odin

from oscar.core.loading import get_class

BaseOrderResource = get_class("oscar_odin.resources.order", "OrderResource")
ShippingAddressResource = get_class(
    "oscar_odin.resources.address", "ShippingAddressResource"
)
BillingAddressResource = get_class(
    "oscar_odin.resources.address", "BillingAddressResource"
)


class SourceTypeResource(odin.AResource):
    class Meta:
        name = "SourceType"

    name: str
    code: str


class OrderResource(BaseOrderResource):
    delivery_time_text: Optional[str]
    delivery_time_days: Optional[int]
    delivery_date = odin.DateTimeField(null=True)

    payment_source_type: Optional[SourceTypeResource]
    billing_address: Optional[BillingAddressResource]
    shipping_address: Optional[ShippingAddressResource]

    class Meta:
        allow_field_shadowing = True
