import logging


def fuel_or_cargo_spill(oil_attrs, vessel_type, random_generator):
    """Randomly choose whether the spill is from fuel or cargo volume for vessel types that
    transport oil as cargo.

    :param dict oil_attrs: Oil attribution information from the output of make_oil_attrs.py.

    :param str vessel_type: Vessel type from which spill occurs.

    :param random_generator: PCG-64 random number generator.
    :type random_generator: :py:class:`numpy.random.Generator`

    :return: Fuel or cargo spill flag.
    :rtype: boolean
    """
    logging.info(
        f"Selecting fuel or cargo spill from {vessel_type} vessel weighted by oil attribution "
        f"analysis fuel/cargo spill probabilities"
    )
    try:
        fuel_spill = random_generator.choice(
            [False, True],
            p=[
                oil_attrs["vessel_attributes"][vessel_type]["probability_cargo"],
                oil_attrs["vessel_attributes"][vessel_type]["probability_fuel"],
            ],
        )
    except KeyError:
        # No probability_cargo or probability_fuel key means that vessel type carries only fuel
        fuel_spill = True
    return fuel_spill