# Path: mgz/fast/header.py
# def parse(data):
#     """Parse recorded game header."""
#     try:
#         header = decompress(data)
#         version, game, save, log = parse_version(header, data)
#         if version not in (Version.USERPATCH15, Version.DE, Version.HD):
#             raise RuntimeError(f"{version} not supported")
#         de = parse_de(header, version, save)
#         hd = parse_hd(header, version, save)
#         metadata, num_players = parse_metadata(header)
#         map_ = parse_map(header, version)
#         players, mod = parse_players(header, num_players, version)
#         scenario = parse_scenario(header, num_players, version, save)
#         lobby = parse_lobby(header, version, save)
#     except (struct.error, zlib.error, AssertionError, MemoryError):
#         raise RuntimeError("could not parse")
#     return dict(
#         version=version,
#         game_version=game,
#         save_version=save,
#         log_version=log,
#         players=players,
#         map=map_,
#         de=de,
#         hd=hd,
#         mod=mod,
#         metadata=metadata,
#         scenario=scenario,
#         lobby=lobby
#     )
# 
# Path: mgz/util.py
# class Version(Enum):
#     """Version enumeration.
# 
#     Using consts from https://github.com/goto-bus-stop/recanalyst/blob/master/src/Model/Version.php
#     for consistency.
#     """
#     AOK = 1
#     AOC = 4
#     AOC10 = 5
#     AOC10C = 8
#     USERPATCH12 = 12
#     USERPATCH13 = 13
#     USERPATCH14 = 11
#     USERPATCH15 = 20
#     DE = 21
#     USERPATCH14RC2 = 22
#     MCP = 30
#     HD = 19


import unittest
from mgz.fast.header import parse
from mgz.util import Version

class TestFastUserPatch15(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        with open('tests/recs/small.mgz', 'rb') as handle:
            cls.data = parse(handle)

    def test_version(self):
        self.assertEqual(self.data['version'], Version.USERPATCH15)

    def test_players(self):
        players = self.data.get('players')
        self.assertEqual(len(players), 3)
        self.assertEqual(players[0]['diplomacy'], [1, 4, 4, -1, -1, -1, -1, -1, -1])
        self.assertEqual(players[1]['diplomacy'], [0, 1, 4, -1, -1, -1, -1, -1, -1])
        self.assertEqual(players[2]['diplomacy'], [0, 4, 1, -1, -1, -1, -1, -1, -1])

    def test_map(self):
        self.assertEqual(self.data['scenario']['map_id'], 44)


class TestFastDE(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        with open('tests/recs/de-13.34.aoe2record', 'rb') as handle:

# Path: mgz/fast/header.py
# def parse(data):
#     """Parse recorded game header."""
#     try:
#         header = decompress(data)
#         version, game, save, log = parse_version(header, data)
#         if version not in (Version.USERPATCH15, Version.DE, Version.HD):
#             raise RuntimeError(f"{version} not supported")
#         de = parse_de(header, version, save)
#         hd = parse_hd(header, version, save)
#         metadata, num_players = parse_metadata(header)
#         map_ = parse_map(header, version)
#         players, mod = parse_players(header, num_players, version)
#         scenario = parse_scenario(header, num_players, version, save)
#         lobby = parse_lobby(header, version, save)
#     except (struct.error, zlib.error, AssertionError, MemoryError):
#         raise RuntimeError("could not parse")
#     return dict(
#         version=version,
#         game_version=game,
#         save_version=save,
#         log_version=log,
#         players=players,
#         map=map_,
#         de=de,
#         hd=hd,
#         mod=mod,
#         metadata=metadata,
#         scenario=scenario,
#         lobby=lobby
#     )
# 
# Path: mgz/util.py
# class Version(Enum):
#     """Version enumeration.
# 
#     Using consts from https://github.com/goto-bus-stop/recanalyst/blob/master/src/Model/Version.php
#     for consistency.
#     """
#     AOK = 1
#     AOC = 4
#     AOC10 = 5
#     AOC10C = 8
#     USERPATCH12 = 12
#     USERPATCH13 = 13
#     USERPATCH14 = 11
#     USERPATCH15 = 20
#     DE = 21
#     USERPATCH14RC2 = 22
#     MCP = 30
#     HD = 19


# Path: tests/test_fast.py
import unittest
from mgz.fast.header import parse
from mgz.util import Version


class TestFastUserPatch15(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        with open('tests/recs/small.mgz', 'rb') as handle:
            cls.data = parse(handle)

    def test_version(self):
        self.assertEqual(self.data['version'], Version.USERPATCH15)

    def test_players(self):
        players = self.data.get('players')
        self.assertEqual(len(players), 3)
        self.assertEqual(players[0]['diplomacy'], [1, 4, 4, -1, -1, -1, -1, -1, -1])
        self.assertEqual(players[1]['diplomacy'], [0, 1, 4, -1, -1, -1, -1, -1, -1])
        self.assertEqual(players[2]['diplomacy'], [0, 4, 1, -1, -1, -1, -1, -1, -1])

    def test_map(self):
        self.assertEqual(self.data['scenario']['map_id'], 44)


class TestFastDE(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        with open('tests/recs/de-13.34.aoe2record', 'rb') as handle:

            cls.data = parse(handle)