from aws_lambda_powertools.event_handler.api_gateway import Router

from boto3clients import s3_client
from config import BUCKET_NAME

router = Router()


@router.get('/<enrollment_id>/download')
def download(enrollment_id: str):
    params = {
        'Bucket': BUCKET_NAME,
        'Key': f'certs/{enrollment_id}.pdf',
        'ResponseContentDisposition': f'attachment; filename="{enrollment_id}.pdf"',
    }
    return {
        'presigned_url': s3_client.generate_presigned_url(
            ClientMethod='get_object',
            Params=params,
            ExpiresIn=300,  # 5 minutes
        )
    }
