"""Helper functions for generate_attachments lambda integration tests.""" from typing import Any from sqlalchemy.orm import Session from tests.src.utils import poll_until_status def poll_until_status_complete( db_session: Session, statement_attachment_id: int, conditions: dict[str, Any], timeout: int = 30, poll_interval: int = 5, target_status: str = 'complete', ) -> dict[str, Any]: """Poll until statement_attachment_status reaches the target status for the given statement_attachment_id. Args: db_session: Active SQLAlchemy database session. statement_attachment_id: ID to invoke generate_attachments lambda. conditions: Additional filter conditions (e.g. {'account_id': x} or {'account_id': x, 'subaccount_id': y}). timeout: Maximum seconds to wait before raising TimeoutError. Defaults to 30. poll_interval: Seconds to wait between each poll attempt. Defaults to 5. target_status: The status to poll for. Defaults to 'complete'. Returns: The matching statement_attachment row as a dict once status reaches target_status. Raises: TimeoutError: when the status does not reach target_status within *timeout* seconds. """ return poll_until_status( db_session, table='statement_attachment', id_column='statement_attachment_id', record_id=statement_attachment_id, status_column='statement_attachment_status', conditions=conditions, timeout=timeout, poll_interval=poll_interval, target_status=target_status, )