from typing import List
from typing import Tuple


def boundingbox_intersection(
    box1: List[int],
    box2: List[int]
) -> Tuple[int, List[int]]:
    """
    Compute the intersection of two bounding boxes.

    The bounding boxes have the notation [xmin, ymin, XMAX, YMAX].

    Args
    ----
        box1: the first bounding box.
        box2: the second bounding box.

    Returns
    -------
        area: the area of intersection.
        bounding_box: the resulting intersection bounding_box

    Note
    ----
        The area is expressed in terms of geometric area!
        The area intended as number of pixels, can be computed by the geometric features
        that can be obtained from the bounding box:
        PIXELS = area + perimeter/2 + 1

    """
    xmin_b1 = int(box1[0])
    xMAX_b1 = int(box1[2])
    ymin_b1 = int(box1[1])
    yMAX_b1 = int(box1[3])
    xmin_b2 = int(box2[0])
    xMAX_b2 = int(box2[2])
    ymin_b2 = int(box2[1])
    yMAX_b2 = int(box2[3])

    if (xmin_b2 > xMAX_b1) or (ymin_b2 > yMAX_b1) or (xMAX_b2 < xmin_b1) or (yMAX_b2 < ymin_b1):
        # No intersection
        area = 0
        bounding_box = []
    else:
        # There is intersection
        xmin = max(xmin_b1, xmin_b2)
        ymin = max(ymin_b1, ymin_b2)
        xMAX = min(xMAX_b1, xMAX_b2)
        yMAX = min(yMAX_b1, yMAX_b2)
        bounding_box = [xmin, ymin, xMAX, yMAX]
        # geometric area is width*height
        area = (xMAX - xmin)*(yMAX - ymin)

    return area, bounding_box