from typing import Callable
from pathlib import Path


def template_file(tmp_file: Callable[[str, str], Path]) -> Callable[[str, str], Path]:
    """
    Retrieve a path to a file from the test templates/

    All these files mirror each other for every file type
    so that one test can run on all the different file types.

    Args:
        file_type: The filetype to retrieve i.e. "ini"
        template_name: The name of the template to retrieve.
            Defaults to the "default" template. i.e. the template
            with the name "default" with it's respective file extension.

    Returns:
        A Path object point to that test template.
    """
    template_dir = Path(__file__).parent / "templates"

    def func(file_type: str, template_name: str = "default") -> Path:
        file_name = f"{template_name}.{file_type}"
        template = template_dir / file_type / file_name

        return tmp_file(file_name, template.read_text(encoding="utf-8"))

    return func