from typing import List, Optional
from datetime import datetime
from pydantic import BaseModel

# Base schema with common attributes
class BoxBase(BaseModel):
    name: str
    description: Optional[str] = None
    game_id: int
    set_id: Optional[int] = None
    price: Optional[float] = None
    quantity: Optional[int] = 0
    status: Optional[str] = "available"  # available, sold, reserved

# Schema for creating a new box
class BoxCreate(BoxBase):
    pass

# Schema for updating a box
class BoxUpdate(BoxBase):
    pass

# Schema for reading a box
class BoxInDB(BoxBase):
    id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True

# Schema for deleting a box
class BoxDelete(BaseModel):
    message: str

# Schema for listing boxes
class BoxList(BaseModel):
    boxes: List[BoxInDB]
    total: int
    page: int
    limit: int

# OpenBox schemas
class OpenBoxBase(BaseModel):
    box_id: int
    opened_at: Optional[datetime] = None
    opened_by: Optional[str] = None
    contents: Optional[List[dict]] = None
    status: Optional[str] = "pending"  # pending, opened, verified, listed

class OpenBoxCreate(OpenBoxBase):
    pass

class OpenBoxUpdate(OpenBoxBase):
    pass

class OpenBoxInDB(OpenBoxBase):
    id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True

class OpenBoxDelete(BaseModel):
    message: str

class OpenBoxList(BaseModel):
    open_boxes: List[OpenBoxInDB]
    total: int
    page: int
    limit: int 