from pdf_text_image_xtract import PDFTextImageExtractor
import time
from pathlib import Path
from typing import List


def test_process():
    extractor = PDFTextImageExtractor(
        "test_pdfs/cv3.pdf"
    )
    start_time = time.time()
    text_data, image_data = extractor.process()
    end_time = time.time()
    print(f"Processing time: {end_time - start_time} seconds")
    assert len(text_data) > 0
    assert len(image_data) > 0


# def test_proess_s3():
#     s3_extractor = PDFTextImageExtractor(
#         "s3://pdf-test-bucket-123123132dsf/policy_schedule.pdf"
#     )
#     start_time = time.time()
#     text_data, image_data = s3_extractor.process()
#     end_time = time.time()
#     print(f"Processing time (from s3): {end_time - start_time} seconds")
#     assert len(text_data) > 0
#     assert len(image_data) > 0

# def test_save_to_s3():
#     extractor = PDFTextImageExtractor("test_pdfs/policy_schedule.pdf")
#     text_data, image_data = extractor.process()
#     responses1 = extractor.save_text_data_to_json_s3(
#         "pdf-test-bucket-123123132dsf", "output/policy_schedule.json"
#     )
#     responses2 = extractor.save_images_to_s3("pdf-test-bucket-123123132dsf", "output/images")

#     assert responses1
#     assert responses2


def get_pdfs(folder_path: str) -> list[Path]:
    return list(Path(folder_path).glob("*.pdf"))


def test_machine_pdfs():
    machine_pdf_files = get_pdfs("test_pdfs")
    for pdf_file in machine_pdf_files:
        
        extractor = PDFTextImageExtractor(pdf_file.as_posix())
        extractor.process()
        extractor.save_text_data_as_md(f"output_md/{pdf_file.stem}.md")
        extractor.save_text_data_as_md_s3("pdf-test-bucket-123123132dsf", f"output_md/{pdf_file.stem}.md")
        assert not extractor.is_pdf_scanned

def test_scanned_pdfs():
    scanned_pdf_files = get_pdfs("test_scanned_pdfs")
    for pdf_file in scanned_pdf_files:
        extractor = PDFTextImageExtractor(pdf_file.as_posix())
        assert  extractor.is_pdf_scanned


