from typing import List

from fastapi import APIRouter, HTTPException

from src.db.models.tysc import Card
from src.db.session import SessionDep
from src.schema.tysc.card import CardResponse, to_response


router = APIRouter()

@router.get("/cards")
def get_all_cards(db: SessionDep) -> List[CardResponse]:
    results: List[CardResponse] = []
    cards = db.query(Card).all()
    for card in cards:
        response = to_response(card)
        results.append(response)
    return results

@router.get("/cards/{card_id}", response_model=CardResponse)
def get_card(card_id: str, db: SessionDep) -> CardResponse:
    card = db.get(Card, card_id)
    if card is None:
        raise HTTPException(status_code=404, detail="Card could not be found")
    response = to_response(card)
    return response
