from http import HTTPStatus
from typing import Annotated

from aws_lambda_powertools.event_handler.api_gateway import Router
from aws_lambda_powertools.event_handler.openapi.params import Body
from layercake.dynamodb import (
    DynamoDBPersistenceLayer,
    KeyPair,
)

from api_gateway import JSONResponse
from boto3clients import dynamodb_client
from config import ENROLLMENT_TABLE

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


@router.delete('/<enrollment_id>/dedupwindow', compress=True)
def dedup_window(
    enrollment_id: str,
    lock_hash: Annotated[str, Body(embed=True)],
):
    with dyn.transact_writer() as transact:
        transact.delete(key=KeyPair(enrollment_id, 'LOCK'))
        transact.delete(key=KeyPair('LOCK', lock_hash))

    return JSONResponse(HTTPStatus.NO_CONTENT)
