from aws_lambda_powertools import Logger
from aws_lambda_powertools.event_handler.api_gateway import Router
from layercake.dynamodb import DynamoDBPersistenceLayer, SortKey, TransactKey

from boto3clients import dynamodb_client
from config import ENROLLMENT_TABLE

from .cancel import router as cancel
from .dedup_window import router as dedup_window
from .download_cert import router as download_cert
from .enroll import router as enroll
from .scorm import router as scorm

__all__ = ['cancel', 'dedup_window', 'download_cert', 'enroll', 'scorm']

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


@router.get('/<enrollment_id>')
def get_enrollment(enrollment_id: str):
    return dyn.collection.get_items(
        TransactKey(enrollment_id)
        + SortKey('0')
        + SortKey('ORG', rename_key='org')
        + SortKey('CANCEL_POLICY', rename_key='cancel_policy')
        + SortKey('CREATED_BY', rename_key='created_by')
        + SortKey('CANCELED_BY', rename_key='canceled_by')
        + SortKey('LOCK', rename_key='lock')
    )
