from typing import List

from fastapi import APIRouter, HTTPException

from src.db.models.tysc import Team
from src.db.session import SessionDep
from src.schema.tysc.team import TeamResponse, to_response


router = APIRouter()

@router.get("/teams")
def get_all_teams(db: SessionDep) -> List[TeamResponse]:
    results: list[TeamResponse] = []
    teams = db.query(Team).all()
    for team in teams:
        response = to_response(team)
        results.append(response)
    return results

@router.get("/teams/{team_id}", response_model=TeamResponse)
def get_team(team_id: str, db: SessionDep) -> TeamResponse:
    team = db.get(Team, team_id)
    if team is None:
        raise HTTPException(status_code=404, detail="Team could not be found")
    response = to_response(team)
    return response
