from typing import List, Dict

from fastapi import APIRouter, Depends, HTTPException, Query
from sqlmodel import Session, select

from app import models
from app.api import deps


router = APIRouter()


@router.post("/", response_model=models.TeamRead)
def create_team(
    *, session: Session = Depends(deps.get_session), team: models.TeamCreate
) -> models.Team:
    db_team = models.Team.from_orm(team)
    session.add(db_team)
    session.commit()
    session.refresh(db_team)
    return db_team


@router.get("/", response_model=List[models.TeamRead])
def read_teams(
    *,
    session: Session = Depends(deps.get_session),
    offset: int = 0,
    limit: int = Query(default=100, lte=100),
) -> List[models.Team]:
    teams = session.exec(