from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.db.database import get_db
from app.models.file import File as FileModel
from app.schemas.file import FileCreate, FileUpdate, FileDelete, FileList, FileInDB
from app.models.box import Box as BoxModel, OpenBox as OpenBoxModel
from app.schemas.box import BoxCreate, BoxUpdate, BoxDelete, BoxList, OpenBoxCreate, OpenBoxUpdate, OpenBoxDelete, OpenBoxList, BoxInDB, OpenBoxInDB
from app.models.game import Game as GameModel
from app.schemas.game import GameCreate, GameUpdate, GameDelete, GameList, GameInDB
from app.models.card import Card as CardModel
from app.routes.set_label_routes import router as set_label_router
from app.routes.order_routes import router as order_router

router = APIRouter(prefix="/api")

# Include set label routes
router.include_router(set_label_router)

# Include order routes
router.include_router(order_router)

# ============================================================================
# Health Check & Root Endpoints
# ============================================================================
@router.get("/")
async def root():
    return {"message": "CCR Cards Management API is running."}

@router.get("/health")
async def health():
    return {"status": "ok"}

# ============================================================================
# File Management Endpoints
# ============================================================================
@router.get("/files", response_model=FileList)
async def get_files(page: int = 1, limit: int = 10, type: str = None, id: int = None):
    return {"files": [], "total": 0, "page": page, "limit": limit}

@router.post("/files", response_model=FileInDB)
async def create_file(file: FileCreate):
    return {"message": "File created successfully"}

@router.put("/files/{file_id}", response_model=FileInDB)
async def update_file(file_id: int, file: FileUpdate):
    return {"message": "File updated successfully"}

@router.delete("/files/{file_id}", response_model=FileDelete)
async def delete_file(file_id: int):
    return {"message": "File deleted successfully"}

# ============================================================================
# Box Management Endpoints
# ============================================================================
@router.get("/boxes", response_model=BoxList)
async def get_boxes(page: int = 1, limit: int = 10, type: str = None, id: int = None):
    return {"boxes": [], "total": 0, "page": page, "limit": limit}

@router.post("/boxes", response_model=BoxInDB)
async def create_box(box: BoxCreate):
    return {"message": "Box created successfully"}

@router.put("/boxes/{box_id}", response_model=BoxInDB)
async def update_box(box_id: int, box: BoxUpdate):
    return {"message": "Box updated successfully"}

@router.delete("/boxes/{box_id}", response_model=BoxDelete)
async def delete_box(box_id: int):
    return {"message": "Box deleted successfully"}

# ============================================================================
# Open Box Management Endpoints
# ============================================================================
@router.get("/open_boxes", response_model=OpenBoxList)
async def get_open_boxes(page: int = 1, limit: int = 10, type: str = None, id: int = None):
    return {"open_boxes": [], "total": 0, "page": page, "limit": limit}

@router.post("/open_boxes", response_model=OpenBoxInDB)
async def create_open_box(open_box: OpenBoxCreate):
    return {"message": "Open box created successfully"}

@router.put("/open_boxes/{open_box_id}", response_model=OpenBoxInDB)
async def update_open_box(open_box_id: int, open_box: OpenBoxUpdate):
    return {"message": "Open box updated successfully"}

@router.delete("/open_boxes/{open_box_id}", response_model=OpenBoxDelete)
async def delete_open_box(open_box_id: int):
    return {"message": "Open box deleted successfully"}

# ============================================================================
# Game Management Endpoints
# ============================================================================
@router.get("/games", response_model=GameList)
async def get_games(page: int = 1, limit: int = 10, type: str = None, id: int = None):
    return {"games": [], "total": 0, "page": page, "limit": limit}

@router.post("/games", response_model=GameInDB)
async def create_game(game: GameCreate):
    return {"message": "Game created successfully"}

@router.put("/games/{game_id}", response_model=GameInDB)
async def update_game(game_id: int, game: GameUpdate):
    return {"message": "Game updated successfully"}

@router.delete("/games/{game_id}", response_model=GameDelete)
async def delete_game(game_id: int):
    return {"message": "Game deleted successfully"}

