"""Helper functions for custom_reports 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, report_custom_id: int, conditions: dict[str, Any], timeout: int = 30, poll_interval: int = 5, target_status: str = 'complete', ) -> dict[str, Any]: """Poll until report_custom_status reaches the target status for the given report_custom_id. Args: db_session: Active SQLAlchemy database session. report_custom_id: ID of the report_custom row being processed. conditions: Additional filter conditions (e.g. {'account_id': x}). 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 report_custom 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='report_custom', id_column='report_custom_id', record_id=report_custom_id, status_column='report_custom_status', conditions=conditions, timeout=timeout, poll_interval=poll_interval, target_status=target_status, )