from typing import List, Optional, Dict
from sqlalchemy.orm import Session
from app.models.inventory import Inventory
from app.services.base_service import BaseService

class InventoryService(BaseService[Inventory]):
    def __init__(self):
        super().__init__(Inventory)

    def create(self, db: Session, obj_in: Dict) -> Inventory:
        """
        Create a new inventory item in the database.
        
        Args:
            db: Database session
            obj_in: Dictionary containing inventory data
            
        Returns:
            Inventory: The created inventory object
        """
        return super().create(db, obj_in)

    def update(self, db: Session, db_obj: Inventory, obj_in: Dict) -> Inventory:
        """
        Update an existing inventory item in the database.
        
        Args:
            db: Database session
            db_obj: The inventory object to update
            obj_in: Dictionary containing updated inventory data
            
        Returns:
            Inventory: The updated inventory object
        """
        return super().update(db, db_obj, obj_in)

    def get_by_tcgplayer_id(self, db: Session, tcgplayer_id: str) -> Optional[Inventory]:
        """
        Get an inventory item by its TCGPlayer ID.
        
        Args:
            db: Database session
            tcgplayer_id: The TCGPlayer ID to find
            
        Returns:
            Optional[Inventory]: The inventory item if found, None otherwise
        """
        return db.query(self.model).filter(self.model.tcgplayer_id == tcgplayer_id).first()

    def get_by_set(self, db: Session, set_name: str, skip: int = 0, limit: int = 100) -> List[Inventory]:
        """
        Get all inventory items from a specific set.
        
        Args:
            db: Database session
            set_name: The name of the set to filter by
            skip: Number of records to skip (for pagination)
            limit: Maximum number of records to return
            
        Returns:
            List[Inventory]: List of inventory items from the specified set
        """
        return db.query(self.model).filter(self.model.set_name == set_name).offset(skip).limit(limit).all() 