import os
from typing import Any, Mapping


from utils.logger import setup_logger
from utils.s3 import upload_file_to_s3

logger = setup_logger()

BUCKET = "retrofit-energy-assessments-dev"
PDF_S3_KEY = "example/SiteNotesExample.pdf"
PDF_LOCAL_PATH = os.path.join(
    os.path.dirname(__file__),
    "..",
    "..",
    "tests",
    "test_data",
    "SiteNotesExample.pdf",
)


def upload_pdf(local_path: str, bucket: str, key: str) -> None:
    logger.info(f"Uploading {local_path} to s3://{bucket}/{key}")
    upload_file_to_s3(local_path, bucket, key)
    logger.info("Upload complete")


def handler(event: Mapping[str, Any], context: Any) -> None:
    logger.info("Entered handler")

    output_path = os.path.join(os.path.dirname(__file__), "..", "textract_blocks.json")

    upload_pdf(PDF_LOCAL_PATH, BUCKET, PDF_S3_KEY)

    logger.info(f"Uploaded file to {output_path}")


if __name__ == "__main__":
    handler({}, None)
