from aws_lambda_powertools import Logger
from aws_lambda_powertools.event_handler.api_gateway import Router
from aws_lambda_powertools.event_handler.exceptions import NotFoundError
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair

from boto3clients import dynamodb_client
from config import ENROLLMENT_TABLE

logger = Logger(__name__)
router = Router()
dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)


@router.get('/<org_id>/enrollments/<submission_id>/submitted')
def submitted(org_id: str, submission_id: str):
    return dyn.collection.get_item(
        KeyPair(
            pk=f'SUBMISSION#ORG#{org_id}',
            sk=submission_id,
        ),
        exc_cls=NotFoundError,
    )
