from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session

from .. import models, schemas
from ..database import get_db

router = APIRouter(prefix="/api/technologies", tags=["technologies"])


@router.get("", response_model=list[schemas.TechnologyOut])
def list_technologies(db: Session = Depends(get_db)):
    return db.query(models.Technology).order_by(models.Technology.id).all()


@router.get("/{technology_id}", response_model=schemas.TechnologyOut)
def get_technology(technology_id: int, db: Session = Depends(get_db)):
    technology = db.get(models.Technology, technology_id)
    if technology is None:
        raise HTTPException(status_code=404, detail="Texnologiya topilmadi")
    return technology
