"""This module contains the tasks for the ``media`` app"""

from celery.utils.log import get_task_logger

from mtp.celery import app

from .models import PdfMedia

logger = get_task_logger(__name__)  # pylint: disable=invalid-name


@app.task
def generate_images_from_pdf_media(pdf_media_pk):
    """Task that will generate images from a ``PdfMedia``

    Parameters
    ----------
    pdf_media_pk: str
        The ``PdfMedia`` PK we try to extract the images from

    Returns
    -------
    str
        The absolute path of the folder with the generated images,
        or None if the task is currently in progress

    Notes
    -----
    This task simply load the ``Document`` object and call the ``generate_images_from_pdf``
    method on it.

    """

    pdf_media = PdfMedia.objects.get(pk=pdf_media_pk)

    return pdf_media.generate_images(async=False)
