import os
import sys
from pathlib import Path

import appdirs

app_name = "mouse-scroll-wheel-accelerator"
app_name_human = "Mouse scroll wheel accelerator"

config_dir = Path(appdirs.user_config_dir(appname=app_name))
config_fn = config_dir / "config.py"


def good_default_options():
    """
    Probably very subjective. But just to have some reasonable defaults,
    which might be used.
    This is dependent on the OS.

    Usage in your config might be like::

      import common
      globals().update(common.good_default_options())

    """
    if sys.platform == "darwin":
        # Darwin (MacOSX) already has builtin mouse scroll wheel acceleration,
        # so we should apply much less extra acceleration.
        return {"exp": 0.5}
    # All other common desktop platforms do not (Linux, Windows).
    # (Android does, but we don't expect that here...)
    return {"multiplier": 0.5, "exp": 1.5, "threshold": 2.0}


def install_default_config():
    assert not config_fn.exists()
    print(f"Writing default config file to {config_fn}")
    if not config_dir.exists():
        os.makedirs(config_dir)
    with open(config_fn, "w") as f:
        f.write(
            f"# automatically generated by {app_name} install_default_config()\n"
        )
        for key, value in good_default_options().items():
            f.write(f"{key} = {value!r}\n")
