from aws_lambda_powertools.utilities.typing import LambdaContext
from layercake.dynamodb import (
    DynamoDBPersistenceLayer,
    KeyPair,
)

import events.reporting.send_report_email as app


def test_send_report_email(
    monkeypatch,
    seeds,
    dynamodb_persistence_layer: DynamoDBPersistenceLayer,
    lambda_context: LambdaContext,
):
    pk = 'CERT_REPORTING#ORG#00237409-9384-4692-9be5-b4443a41e1c4'
    event = {
        'detail': {
            'old_image': {
                'id': pk,
                'sk': 'MONTH#2025-06#SCHEDULE#SEND_REPORT_EMAIL',
                'target_month': '2025-07',
            },
        }
    }
    monkeypatch.setattr(app.sesv2_client, 'send_email', lambda *args, **kwargs: ...)

    assert app.lambda_handler(event, lambda_context)  # type: ignore

    r = dynamodb_persistence_layer.collection.get_item(KeyPair(pk, 'MONTH#2025-06'))
    assert r['status'] == 'CLOSED'
