from typing import List

from fastapi import APIRouter, HTTPException

from src.db.models.tysc import Rooster
from src.db.session import SessionDep
from src.schema.tysc.rooster import RoosterResponse, to_response


router = APIRouter()

@router.get("/roosters")
def get_all_roosters(db: SessionDep) -> List[RoosterResponse]:
    results: list[RoosterResponse] = []
    roosters = db.query(Rooster).all()
    for rooster in roosters:
        response = to_response(rooster)
        results.append(response)
    return results

@router.get("/roosters/{rooster_id}", response_model=RoosterResponse)
def get_rooster(rooster_id: str, db: SessionDep) -> RoosterResponse:
    rooster = db.get(Rooster, rooster_id)
    if rooster is None:
        raise HTTPException(status_code=404, detail="Rooster could not be found")
    response = to_response(rooster)
    return response
