from pathlib import Path


def create_user_unit_path(create_folder: bool = False):
    """

    We want to add a systemd user unit to run transmission-pod on certain times. In order to do
    this we want to crete a unit at a proper location. According to:
    https://wiki.archlinux.org/index.php/Systemd/User
    our options are:

    * /usr/lib/systemd/user/:

      where units provided by installed packages belong.
    * ~/.local/share/systemd/user/

      where units of packages that have been installed in the home directory belong.
    * /etc/systemd/user/

      where system-wide user units are placed by the system administrator.
    * ~/.config/systemd/user/

      where the user puts their own units.

    We opt to use the latter choice.

    This function constructs the proper systemd user unit path where it will be installed.
    It also creates the necessary folder if it doesn't exist.

    :param create_folder: If true create the folder that the unit service will be installed.
    :returns: Path object for the location the unit service will be installed.

    """

    home = Path.home()
    unit_folder_path = home.joinpath(".config", "systemd", "user")
    if create_folder and not unit_folder_path.exists():
        unit_folder_path.mkdir(parents=True)

    unit_path = unit_folder_path.joinpath("transmission-pod.service")
    return unit_path