from __future__ import annotations

from ebay_client.core.http.transport import ApiTransport
from ebay_client.generated.feed.models import (
    ScheduleTemplateCollection,
    Task,
    TaskCollection,
    UserScheduleCollection,
)

FEED_INVENTORY_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.inventory"
FEED_FULFILLMENT_SCOPE = "https://api.ebay.com/oauth/api_scope/sell.fulfillment"


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

    def get_tasks(self, *, feed_type: str | None = None) -> TaskCollection:
        return self.transport.request_model(
            TaskCollection,
            "GET",
            "/sell/feed/v1/task",
            scopes=[FEED_INVENTORY_SCOPE, FEED_FULFILLMENT_SCOPE],
            params={"feed_type": feed_type},
        )

    def get_task(self, task_id: str) -> Task:
        return self.transport.request_model(
            Task,
            "GET",
            f"/sell/feed/v1/task/{task_id}",
            scopes=[FEED_INVENTORY_SCOPE, FEED_FULFILLMENT_SCOPE],
        )

    def get_schedule_templates(self) -> ScheduleTemplateCollection:
        return self.transport.request_model(
            ScheduleTemplateCollection,
            "GET",
            "/sell/feed/v1/schedule_template",
            scopes=[FEED_INVENTORY_SCOPE, FEED_FULFILLMENT_SCOPE],
        )

    def get_schedules(self) -> UserScheduleCollection:
        return self.transport.request_model(
            UserScheduleCollection,
            "GET",
            "/sell/feed/v1/schedule",
            scopes=[FEED_INVENTORY_SCOPE, FEED_FULFILLMENT_SCOPE],
        )
