def process_horizons_and_targets(
    horizons: Optional[Union[int, Sequence[int]]] = None,
    fallback_horizon: Optional[int] = None,
    target_components: Optional[Union[str, Sequence[str]]] = None,
    fallback_target_components: Optional[Sequence[str]] = None,
    check_component_names: bool = False,
) -> tuple[Sequence[int], Sequence[str]]:
    """Processes the input horizons and target component names.

    horizons
        Optionally, an integer or sequence of integers representing the future time steps to be explained.
        `1` corresponds to the first timestamp being forecasted.
        All values must be `<=output_chunk_length` of the explained forecasting model.
    fallback_horizon
        Optionally, a horizon to fall back to in case `horizons` was not provided.
    target_components
        Optionally, a string or sequence of strings with the target components to explain.
    fallback_target_components
         Optionally, a sequence of strings to fall back to in case `target_components` was not provided.
    check_component_names
        Whether to enforce that the target components are in `fallback_target_component`.
    """

    if target_components is not None:
        if isinstance(target_components, str):
            target_components = [target_components]
        if check_component_names and fallback_target_components is not None:
            invalid_components = [
                target_name
                for target_name in target_components
                if target_name not in fallback_target_components
            ]
            raise_if(
                len(invalid_components) > 0,
                "Invalid `target_components`. The following components are not in the components of the "
                f"`background_series`: {invalid_components}. Provide some valid components from: "
                f"{fallback_target_components}.",
                logger,
            )
    else:
        target_components = fallback_target_components

    if horizons is not None:
        if isinstance(horizons, int):
            horizons = [horizons]

        if fallback_horizon is not None:
            raise_if(
                max(horizons) > fallback_horizon,
                "At least one of the `horizons` is larger than `output_chunk_length`.",
            )
        raise_if(min(horizons) < 1, "All `horizons` must be `>=1`.")
    else:
        horizons = range(1, fallback_horizon + 1)

    return horizons, target_components
Processes the input horizons and target component names.

    horizons
        Optionally, an integer or sequence of integers representing the future time steps to be explained.
        `1` corresponds to the first timestamp being forecasted.
        All values must be `<=output_chunk_length` of the explained forecasting model.
    fallback_horizon
        Optionally, a horizon to fall back to in case `horizons` was not provided.
    target_components
        Optionally, a string or sequence of strings with the target components to explain.
    fallback_target_components
         Optionally, a sequence of strings to fall back to in case `target_components` was not provided.
    check_component_names
        Whether to enforce that the target components are in `fallback_target_component`.
    
darts/explainability/utils.py