# coding=utf-8

from collections.abc import Iterator
from typing import Any, Annotated

TyArr = list[Any]
TyAo2A = Annotated[list[TyArr], 2]
TyTo3Any = tuple[Any, Any, Any]

TnTo3Any = None | TyTo3Any


class Ao2A:
    """Manage Arrays of two Arrays.

    Provides cross-product iteration over a pair of arrays.
    """

    @staticmethod
    def yield_items(ao2a: TyAo2A, obj: Any) -> Iterator[TnTo3Any]:
        """Yield cross-product tuples ``(item0, item1, obj)`` from two arrays.

        For each element in ``ao2a[0]`` paired with each element in ``ao2a[1]``,
        yields a 3-tuple including *obj*. Yields ``None`` if either array is ``None``.

        :param TyAo2A ao2a: List of exactly two arrays.
        :param Any obj: Object appended to each yielded tuple.
        :yields: ``(item_arr0, item_arr1, obj)`` or ``None``.
        :rtype: Iterator[TnTo3Any]
        """
        if not ao2a or len(ao2a) < 2:
            yield None
            return
        arr0 = ao2a[0]
        arr1 = ao2a[1]
        if arr0 is None or arr1 is None:
            yield None
            return
        else:
            for item_arr0 in arr0:
                for item_arr1 in arr1:
                    yield (item_arr0, item_arr1, obj)
