from __future__ import annotations

from pathlib import Path

DEFAULT_CONFIG = Path('~/.config/nanoshare/config.toml').expanduser()

def write_config(path: Path, *, node: str, url: str, refresh_token: str, token_url: str, source: str = 'nanoshare-cli') -> None:
  path = path.expanduser()
  path.parent.mkdir(parents=True, exist_ok=True)
  content = '\n'.join([
    f'source = "{source}"',
    f'refresh_token = "{refresh_token}"',
    f'token_url = "{token_url}"',
    '',
    '[nodes]',
    f'{node} = "{url.rstrip("/")}"',
    '',
  ])
  path.write_text(content)
  path.chmod(0o600)
