from typing import Union
from pathlib import Path


def add_extension(file_path: Union[str, Path], extension: str) -> Union[str, Path]:
    """Adds the extension to the file path if it is not present.

    Parameters
    ----------
    file_path : Union[str, Path]
        The path to the file.
    extension : str
        The extension to add.

    Returns
    -------
    Union[str, Path]
        The path with the extension.
    """

    if isinstance(extension, str):
        if not extension.startswith("."):
            extension = "." + extension
    else:
        raise TypeError(f"Invalid extension type: {type(extension)}")

    if isinstance(file_path, Path):
        if not file_path.suffix == extension:
            file_path = file_path.with_suffix(extension)
    elif isinstance(file_path, str):
        if not file_path.endswith(extension):
            file_path += extension
    else:
        raise TypeError(f"Invalid file path type: {type(file_path)}")

    return file_path