"""Audit log read repository (tenant-scoped)."""

from __future__ import annotations

import uuid

from sqlalchemy import select
from sqlalchemy.orm import Session

from legate.db.models.audit import AuditLog


def list_for_workspace(
    db: Session, *, workspace_id: uuid.UUID, limit: int = 100, offset: int = 0
) -> list[AuditLog]:
    return list(
        db.scalars(
            select(AuditLog)
            .where(AuditLog.workspace_id == workspace_id)
            .order_by(AuditLog.seq.desc())
            .limit(limit)
            .offset(offset)
        ).all()
    )
