from pathlib import Path

import pytest
from rich.console import Console

from osx_backup.context import Context
from osx_backup.runner import RecordingRunner


@pytest.fixture
def fake_home(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
    home = tmp_path / "home"
    home.mkdir()
    monkeypatch.setenv("HOME", str(home))
    return home


@pytest.fixture
def dest(tmp_path: Path) -> Path:
    d = tmp_path / "dest"
    d.mkdir()
    return d


@pytest.fixture
def ctx(fake_home: Path, dest: Path) -> Context:
    return Context(
        home=fake_home,
        dest=dest,
        runner=RecordingRunner(),
        console=Console(record=True, width=120),
    )


@pytest.fixture
def map_path(tmp_path: Path) -> Path:
    p = tmp_path / "map.toml"
    p.write_text(
        '[[dotfiles]]\npath = ".zshrc"\ndescription = "zsh"\n\n'
        '[[dotfiles]]\npath = ".config/fish"\nexclude = ["fish_variables"]\n\n'
        '[[dotfiles]]\npath = ".ssh"\nsecret = true\n\n'
        '[[dotfiles]]\npath = ".config/gh"\nsecret = true\n'
    )
    return p
