from typing import List

from fastapi import APIRouter, HTTPException

from src.db.models.tysc import CardSet
from src.db.session import SessionDep
from src.schema.tysc.cardset import CardSetResponse, to_response


router = APIRouter()

@router.get("/cardsets")
def get_all_cardsets(db: SessionDep) -> List[CardSetResponse]:
    results: List[CardSetResponse] = []
    cardsets = db.query(CardSet).all()
    for cardset in cardsets:
        response = to_response(cardset)
        results.append(response)
    return results

@router.get("/cardsets/{cardset_id}", response_model=CardSetResponse)
def get_cardset(cardset_id: str, db: SessionDep) -> CardSetResponse:
    cardset = db.get(CardSet, cardset_id)
    if cardset is None:
        raise HTTPException(status_code=404, detail="Cardset could not be found")
    response = to_response(cardset)
    return response
