"""Integration tests for the id11 XRPD and PDF processing."""

from ...bliss_globals import setup_globals
from .. import testing
from ..processors.id11 import DemoId11XrpdProcessor
from .utils import xrpd


@testing.integration_fixture
def id11_processor():
    xrpd_processor = DemoId11XrpdProcessor()
    xrpd_processor.enable(setup_globals.difflab6)
    xrpd_processor._plotter.clear_lima_plots("difflab6")

    xrpd_processor.pdf_enable = False
    # TODO:
    # 1. Only enable when diffpy (proprietary) is installed in the worker environment.
    # 2. PdfGetXSaveNexus has missing parameters 'output_filename', 'detector_name', 'scan'.
    # 3. Validate PDF results in addition to XRPD results.

    yield xrpd_processor

    xrpd_processor.disable()


def id11_demo(expo=0.2, npoints=10):
    test_id11_ct_with_1d_integration(expo=expo)
    test_id11_scan_with_1d_integration(expo=expo, npoints=npoints)


@testing.integration_test
def test_id11_ct_with_1d_integration(
    debug_flint, id11_processor, nrepeats: int = None, expo=0.2
):
    xrpd.test_xrpd_ct_with_1d_integration(
        id11_processor,
        [setup_globals.difflab6, setup_globals.diode1, setup_globals.diode2],
        nrepeats=nrepeats,
        expo=expo,
    )


@testing.integration_test
def test_id11_scan_with_1d_integration(
    debug_flint, id11_processor, nrepeats: int = None, expo=0.2, npoints=10
):
    xrpd.test_xrpd_scan_with_1d_integration(
        [id11_processor],
        [
            setup_globals.difflab6,
            setup_globals.diode1,
            setup_globals.diode2,
        ],
        nrepeats=nrepeats,
        expo=expo,
        npoints=npoints,
    )
