from typing import Annotated

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, KeyPair

from boto3clients import dynamodb_client
from config import USER_TABLE

router = Router()
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)


@router.get('/<user_id>/orgs')
def get_orgs(
    user_id: str,
    start_key: Annotated[str | None, Query] = None,
    limit: Annotated[int, Query(ge=25)] = 25,
):
    return dyn.collection.query(
        # Post-migration (users): rename `orgs#` to `ORG#`
        key=KeyPair(user_id, 'orgs#'),
        start_key=start_key,
        limit=limit,
    )
