from typing import Dict, List, Optional
from app.services.external_api.tcgplayer.base_tcgplayer_service import BaseTCGPlayerService
from sqlalchemy.orm import Session
from app.schemas.file import FileInDB

class TCGPlayerInventoryService(BaseTCGPlayerService):
    def __init__(self):
        super().__init__()

    async def get_tcgplayer_export(self, db: Session, export_type: str) -> FileInDB:
        """
        Get a TCGPlayer Staged Inventory Export, Live Inventory Export, or Pricing Export
        """
        if export_type == "staged":
            endpoint = self.staged_inventory_endpoint
            file_type = "text/csv"
        elif export_type == "live":
            endpoint = self.live_inventory_endpoint
            file_type = "text/csv"
        elif export_type == "pricing":
            endpoint = self.pricing_export_endpoint
            file_type = "text/csv"
        else:
            raise ValueError(f"Invalid export type: {export_type}, must be 'staged', 'live', or 'pricing'")
            
        file_bytes = await self._make_request("GET", endpoint, download_file=True)
        return await self.save_file(
            db=db,
            file_data=file_bytes,
            file_name=f"tcgplayer_{export_type}_export.csv",
            subdir="tcgplayer/inventory",
            file_type=file_type
        )