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

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

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


@router.get("/audit", response_model=list[schemas.AuditLogRead])
def audit_logs(db: Session = Depends(get_db)) -> list[models.AuditLog]:
    return db.query(models.AuditLog).order_by(models.AuditLog.created_at.desc()).limit(200).all()


@router.get("/tasks", response_model=list[schemas.TaskRunRead])
def task_logs(db: Session = Depends(get_db)) -> list[models.TaskRun]:
    return db.query(models.TaskRun).order_by(models.TaskRun.created_at.desc()).limit(200).all()

