# Path: crowd_anki/anki/adapters/anki_deck.py
# class AnkiDeck:
#     _data: dict
# 
#     deck_name_separator = '::'
# 
#     @property
#     def data(self):
#         return self._data
# 
#     @property
#     def is_dynamic(self):
#         return bool(self.data['dyn'])
# 
#     @property
#     def name(self):
#         return self.data['name']
# 
# Path: crowd_anki/history/anki_deck_archiver.py
# class AnkiDeckArchiver(Archiver):
#     deck: AnkiDeck
#     output_directory: Path
#     deck_exporter: DeckExporter
#     repo_provider: Callable[[Path], AnkiRepo]
# 
#     def archive(self, _: Iterable = tuple(), reason=None):
#         deck_path = self.deck_exporter.export_to_directory(self.deck, self.output_directory)
# 
#         repo = self.repo_provider(deck_path)
#         repo.stage_all()
#         repo.commit(reason)
#         repo.close()


from mamba import description, it, _it
from pathlib import Path
from unittest.mock import MagicMock
from crowd_anki.anki.adapters.anki_deck import AnkiDeck
from crowd_anki.history.anki_deck_archiver import AnkiDeckArchiver


with description(AnkiDeckArchiver) as self:
    with it("inits repo, archives the deck there and commits"):
        base_path = Path('dummy_dir')
        deck_path = base_path.joinpath('deck_name')

        deck_exporter_mock = MagicMock()
        deck_exporter_mock.export_to_directory.return_value = deck_path

        repo_mock = MagicMock()
        deck = AnkiDeck({})
        archival_reason = "whee"


# Path: crowd_anki/anki/adapters/anki_deck.py
# class AnkiDeck:
#     _data: dict
# 
#     deck_name_separator = '::'
# 
#     @property
#     def data(self):
#         return self._data
# 
#     @property
#     def is_dynamic(self):
#         return bool(self.data['dyn'])
# 
#     @property
#     def name(self):
#         return self.data['name']
# 
# Path: crowd_anki/history/anki_deck_archiver.py
# class AnkiDeckArchiver(Archiver):
#     deck: AnkiDeck
#     output_directory: Path
#     deck_exporter: DeckExporter
#     repo_provider: Callable[[Path], AnkiRepo]
# 
#     def archive(self, _: Iterable = tuple(), reason=None):
#         deck_path = self.deck_exporter.export_to_directory(self.deck, self.output_directory)
# 
#         repo = self.repo_provider(deck_path)
#         repo.stage_all()
#         repo.commit(reason)
#         repo.close()


# Path: test/history/anki_deck_archiver_spec.py
from mamba import description, it, _it
from pathlib import Path
from unittest.mock import MagicMock
from crowd_anki.anki.adapters.anki_deck import AnkiDeck
from crowd_anki.history.anki_deck_archiver import AnkiDeckArchiver



with description(AnkiDeckArchiver) as self:
    with it("inits repo, archives the deck there and commits"):
        base_path = Path('dummy_dir')
        deck_path = base_path.joinpath('deck_name')

        deck_exporter_mock = MagicMock()
        deck_exporter_mock.export_to_directory.return_value = deck_path

        repo_mock = MagicMock()
        deck = AnkiDeck({})
        archival_reason = "whee"


        AnkiDeckArchiver(deck, base_path, deck_exporter_mock, lambda _: repo_mock).archive(reason=archival_reason)