from typing import Annotated

from aws_lambda_powertools import Logger
from aws_lambda_powertools.event_handler.api_gateway import Router
from aws_lambda_powertools.event_handler.openapi.params import Query
from layercake.dynamodb import DynamoDBPersistenceLayer, PartitionKey

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/scheduled')
def scheduled(org_id: str, start_key: Annotated[str | None, Query] = None):
    return dyn.collection.query(
        # Post-migration: rename `scheduled_items` to `SCHEDULED#ORG#{org_id}`
        key=PartitionKey(f'scheduled_items#{org_id}'),
        start_key=start_key,
        limit=150,
    )
