import asyncio
import os
from models.pptx_models import (
    PptxAutoShapeBoxModel,
    PptxFillModel,
    PptxPositionModel,
    PptxPresentationModel,
    PptxSlideModel,
)
from services.pptx_presentation_creator import PptxPresentationCreator
from pptx.enum.shapes import MSO_AUTO_SHAPE_TYPE
from pptx import Presentation


pptx_model = PptxPresentationModel(
    slides=[
        PptxSlideModel(
            shapes=[
                PptxAutoShapeBoxModel(
                    type=MSO_AUTO_SHAPE_TYPE.RECTANGLE,
                    position=PptxPositionModel(
                        left=20,
                        right=20,
                        width=100,
                        height=100,
                    ),
                    fill=PptxFillModel(
                        color="000000",
                        opacity=0.5,
                    ),
                )
            ]
        )
    ]
)


def test_pptx_creator():
    temp_dir = "/tmp/deckforge_test"
    os.makedirs(temp_dir, exist_ok=True)
    save_path = "/tmp/deckforge_test/test_output.pptx"

    pptx_creator = PptxPresentationCreator(pptx_model, temp_dir)
    asyncio.run(pptx_creator.create_ppt())
    pptx_creator.save(save_path)

    assert os.path.exists(save_path), f"PPTX file was not created at {save_path}"
    assert os.path.getsize(save_path) > 0, "PPTX file is empty"

    prs = Presentation(save_path)
    assert len(prs.slides) == 1, f"Expected 1 slide, got {len(prs.slides)}"
