import pprint

import app.events.stopgap.enroll as app
from aws_lambda_powertools.utilities.typing import LambdaContext
from layercake.dynamodb import (
    DynamoDBPersistenceLayer,
    SortKey,
    TransactKey,
)


def test_enroll(
    dynamodb_seeds,
    dynamodb_client,
    dynamodb_persistence_layer: DynamoDBPersistenceLayer,
    lambda_context: LambdaContext,
):
    event = {
        'detail': {
            'new_image': {
                'id': '47ZxxcVBjvhDS5TE98tpfQ',
                'sk': '0',
                'course': {
                    'id': '57',
                    'name': 'NR-33 Supervisor em Espaço Confinado',
                    'time_in_days': 360,
                },
            }
        }
    }
    assert app.lambda_handler(event, lambda_context)  # type: ignore

    result = dynamodb_persistence_layer.collection.get_items(
        TransactKey('47ZxxcVBjvhDS5TE98tpfQ')
        + SortKey('0')
        + SortKey('metadata#deduplication_window')
        + SortKey('metadata#course')
    )

    pprint.pprint(result)
