from __future__ import annotations

from ebay_client.core.http.transport import ApiTransport
from ebay_client.generated.inventory.models import (
    InventoryItemWithSkuLocaleGroupid,
    InventoryItems,
    OfferResponseWithListingId,
    Offers,
)

INVENTORY_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.inventory"
INVENTORY_READ_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.inventory.readonly"
INVENTORY_READ_SCOPE_OPTIONS = [[INVENTORY_READ_SCOPE], [INVENTORY_SCOPE]]


class InventoryClient:
    def __init__(self, transport: ApiTransport) -> None:
        self.transport = transport

    def get_inventory_item(self, sku: str) -> InventoryItemWithSkuLocaleGroupid:
        return self.transport.request_model(
            InventoryItemWithSkuLocaleGroupid,
            "GET",
            f"/sell/inventory/v1/inventory_item/{sku}",
            scope_options=INVENTORY_READ_SCOPE_OPTIONS,
        )

    def get_inventory_items(self, *, limit: int | None = None, offset: int | None = None) -> InventoryItems:
        return self.transport.request_model(
            InventoryItems,
            "GET",
            "/sell/inventory/v1/inventory_item",
            scope_options=INVENTORY_READ_SCOPE_OPTIONS,
            params={"limit": limit, "offset": offset},
        )

    def get_offer(self, offer_id: str) -> OfferResponseWithListingId:
        return self.transport.request_model(
            OfferResponseWithListingId,
            "GET",
            f"/sell/inventory/v1/offer/{offer_id}",
            scope_options=INVENTORY_READ_SCOPE_OPTIONS,
        )

    def get_offers(self, *, limit: int | None = None, offset: int | None = None, sku: str | None = None) -> Offers:
        return self.transport.request_model(
            Offers,
            "GET",
            "/sell/inventory/v1/offer",
            scope_options=INVENTORY_READ_SCOPE_OPTIONS,
            params={"limit": limit, "offset": offset, "sku": sku},
        )
