from decimal import Decimal

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

import events.stopgap.schedule_expired as app


def test_schedule_expired(
    dynamodb_client,
    dynamodb_persistence_layer: DynamoDBPersistenceLayer,
    lambda_context: LambdaContext,
):
    event = {
        'detail': {
            'new_image': {
                'id': '123',
                'sk': '0',
                'due_date': '2025-07-04T08:34:45.780000-03:00',
            }
        }
    }

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

    expected = {
        'sk': 'schedules#set_as_expired',
        'ttl': Decimal('1751715285'),
        'id': '123',
    }
    r = dynamodb_persistence_layer.get_item(
        key=KeyPair('123', 'schedules#set_as_expired')
    )
    assert r['ttl'] == expected['ttl']
