using System.Threading.Tasks;
using NUnit.Framework;
using Robust.Shared.ContentPack;
using Robust.Shared.EntitySerialization;
using Robust.Shared.EntitySerialization.Components;
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Utility;
using static Robust.UnitTesting.Shared.EntitySerialization.EntitySaveTestComponent;

namespace Robust.UnitTesting.Shared.EntitySerialization;

[TestFixture]
public sealed partial class BackwardsCompatibilityTest
{
    /// <summary>
    /// Check that v3 maps can be loaded. This simply tries to load a file and doesn't do a lot of extra validation.
    /// </summary>
    /// <remarks>
    /// The file was pilfered from content integration tests ("floor3x3.yml") and modified slightly.
    /// See also the comments around <see cref="EntityDeserializer.OldestSupportedVersion"/> that point out that v3
    /// isn't even really loadable anymore.
    /// </remarks>
    [Test]
    public async Task TestLoadV3()
    {
        var server = StartServer(new ServerIntegrationOptions {ExtraPrototypes = PrototypeV3});
        await server.WaitIdleAsync();
        var entMan = server.EntMan;
        var mapSys = server.System<SharedMapSystem>();
        var loader = server.System<MapLoaderSystem>();
        var meta = server.System<MetaDataSystem>();
        var tileMan = server.ResolveDependency<ITileDefinitionManager>();
        var resourceManager = server.ResolveDependency<IResourceManagerInternal>();

        tileMan.Register(new TileDef("Space"));
        for (var i = 1; i <= 88; i++)
        {
            tileMan.Register(new TileDef(i.ToString()));
        }
        var gridPath = new ResPath($"{nameof(MapDataV3Grid)}.yml");
        resourceManager.MountString(gridPath.ToString(), MapDataV3Grid);

        MapId mapId = default;
        EntityUid mapUid = default;

        Entity<TransformComponent, EntitySaveTestComponent> map;
        Entity<TransformComponent, EntitySaveTestComponent> ent;
        Entity<TransformComponent, EntitySaveTestComponent> grid;

        Assert.That(entMan.Count<EntitySaveTestComponent>(), Is.EqualTo(0));
        await server.WaitPost(() => mapUid = mapSys.CreateMap(out mapId));
        await server.WaitPost(() => Assert.That(loader.TryLoadGrid(mapId, gridPath, out _)));

        Assert.That(entMan.Count<LoadedMapComponent>(), Is.EqualTo(0));
        Assert.That(entMan.Count<EntitySaveTestComponent>(), Is.EqualTo(2));
        ent = Find(nameof(ent), entMan);
        grid = Find(nameof(grid), entMan);

        Assert.That(ent.Comp1.ParentUid, Is.EqualTo(grid.Owner));
        Assert.That(grid.Comp1.ParentUid, Is.EqualTo(mapUid));

        Assert.That(meta.EntityPaused(ent), Is.False);
        Assert.That(meta.EntityPaused(grid), Is.False);
        Assert.That(meta.EntityPaused(mapUid), Is.False);

        Assert.That(entMan.GetComponent<MetaDataComponent>(ent).EntityLifeStage,
            Is.EqualTo(EntityLifeStage.MapInitialized));
        Assert.That(entMan.GetComponent<MetaDataComponent>(grid).EntityLifeStage,
            Is.EqualTo(EntityLifeStage.MapInitialized));
        Assert.That(entMan.GetComponent<MetaDataComponent>(mapUid).EntityLifeStage,
            Is.EqualTo(EntityLifeStage.MapInitialized));

        await server.WaitPost(() => entMan.DeleteEntity(mapUid));
        Assert.That(entMan.Count<EntitySaveTestComponent>(), Is.EqualTo(0));

        var mapPath = new ResPath($"{nameof(MapDataV3Map)}.yml");
        resourceManager.MountString(mapPath.ToString(), MapDataV3Map);
        await server.WaitPost(() => Assert.That(loader.TryLoadMap(mapPath, out _, out _)));

        Assert.That(entMan.Count<LoadedMapComponent>(), Is.EqualTo(1));
        Assert.That(entMan.Count<EntitySaveTestComponent>(), Is.EqualTo(3));

        ent = Find(nameof(ent), entMan);
        grid = Find(nameof(grid), entMan);
        map = Find(nameof(map), entMan);

        Assert.That(ent.Comp1.ParentUid, Is.EqualTo(grid.Owner));
        Assert.That(grid.Comp1.ParentUid, Is.EqualTo(map.Owner));
        Assert.That(map.Comp1.ParentUid, Is.EqualTo(EntityUid.Invalid));

        Assert.That(meta.EntityPaused(ent), Is.True);
        Assert.That(meta.EntityPaused(grid), Is.True);
        Assert.That(meta.EntityPaused(map), Is.True);

        Assert.That(entMan.GetComponent<MetaDataComponent>(ent).EntityLifeStage,
            Is.EqualTo(EntityLifeStage.Initialized));
        Assert.That(entMan.GetComponent<MetaDataComponent>(grid).EntityLifeStage,
            Is.EqualTo(EntityLifeStage.Initialized));
        Assert.That(entMan.GetComponent<MetaDataComponent>(map).EntityLifeStage,
            Is.EqualTo(EntityLifeStage.Initialized));

        await server.WaitPost(() => entMan.DeleteEntity(map));
        Assert.That(entMan.Count<EntitySaveTestComponent>(), Is.EqualTo(0));

        // Repeat test, but with the initialize maps option enabled.
        // Apparently mounted strings can only be read a single time.
        // So have to re-mount them.
        var mapPath2 = new ResPath($"{nameof(MapDataV3Map)}2.yml");
        resourceManager.MountString(mapPath2.ToString(), MapDataV3Map);

        var opts = DeserializationOptions.Default with {InitializeMaps = true};
        await server.WaitPost(() => Assert.That(loader.TryLoadMap(mapPath2, out _, out _, opts)));

        Assert.That(entMan.Count<LoadedMapComponent>(), Is.EqualTo(1));
        Assert.That(entMan.Count<EntitySaveTestComponent>(), Is.EqualTo(3));

        ent = Find(nameof(ent), entMan);
        grid = Find(nameof(grid), entMan);
        map = Find(nameof(map), entMan);

        Assert.That(ent.Comp1.ParentUid, Is.EqualTo(grid.Owner));
        Assert.That(grid.Comp1.ParentUid, Is.EqualTo(map.Owner));
        Assert.That(map.Comp1.ParentUid, Is.EqualTo(EntityUid.Invalid));

        Assert.That(meta.EntityPaused(ent), Is.False);
        Assert.That(meta.EntityPaused(grid), Is.False);
        Assert.That(meta.EntityPaused(map), Is.False);

        Assert.That(entMan.GetComponent<MetaDataComponent>(ent).EntityLifeStage,
            Is.EqualTo(EntityLifeStage.MapInitialized));
        Assert.That(entMan.GetComponent<MetaDataComponent>(grid).EntityLifeStage,
            Is.EqualTo(EntityLifeStage.MapInitialized));
        Assert.That(entMan.GetComponent<MetaDataComponent>(map).EntityLifeStage,
            Is.EqualTo(EntityLifeStage.MapInitialized));

        await server.WaitPost(() => entMan.DeleteEntity(map));
        Assert.That(entMan.Count<EntitySaveTestComponent>(), Is.EqualTo(0));
    }

    private const string MapDataV3Grid = @"
meta:
  format: 3
  name: DemoStation
  author: Space-Wizards
  postmapinit: false
tilemap:
  0: Space
  1: 1
  2: 2
  3: 3
  4: 4
  5: 5
  6: 6
  7: 7
  8: 8
  9: 9
  10: 10
  11: 11
  12: 12
  13: 13
  14: 14
  15: 15
  16: 16
  17: 17
  18: 18
  19: 19
  20: 20
  21: 21
  22: 22
  23: 23
  24: 24
  25: 25
  26: 26
  27: 27
  28: 28
  29: 29
  30: 30
  31: 31
  32: 32
  33: 33
  34: 34
  35: 35
  36: 36
  37: 37
  38: 38
  39: 39
  40: 40
  41: 41
  42: 42
  43: 43
  44: 44
  45: 45
  46: 46
  47: 47
  48: 48
  49: 49
  50: 50
  51: 51
  52: 52
  53: 53
  54: 54
  55: 55
  56: 56
  57: 57
  58: 58
  59: 59
  60: 60
  61: 61
  62: 62
  63: 63
  64: 64
  65: 65
  66: 66
  67: 67
  68: 68
  69: 69
  70: 70
  71: 71
  72: 72
  73: 73
  74: 74
  75: 75
  76: 76
  77: 77
  78: 78
  79: 79
  80: 80
  81: 81
  82: 82
  83: 83
  84: 84
  85: 85
  86: 86
  87: 87
  88: 88
entities:
- uid: 0
  components:
  - type: MetaData
  - parent: null
    type: Transform
  - chunks:
      -1,-1:
        ind: -1,-1
        tiles: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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apGrid
  - type: Broadphase
  - angularDamping: 0.05
    linearDamping: 0.05
    fixedRotation: False
    bodyType: Dynamic
    type: Physics
  - fixtures: {}
    type: Fixtures
  - type: OccluderTree
  - id: grid
    type: EntitySaveTest
- uid: 1
  type: V3TestProto
  components:
  - pos: 0.5,0.5
    parent: 0
    type: Transform
  - id: ent
    type: EntitySaveTest
...
";

    private const string MapDataV3Map = @"
meta:
  format: 3
  name: DemoStation
  author: Space-Wizards
  postmapinit: false
tilemap:
  0: Space
  1: 1
  2: 2
  3: 3
  4: 4
  5: 5
  6: 6
  7: 7
  8: 8
  9: 9
  10: 10
  11: 11
  12: 12
  13: 13
  14: 14
  15: 15
  16: 16
  17: 17
  18: 18
  19: 19
  20: 20
  21: 21
  22: 22
  23: 23
  24: 24
  25: 25
  26: 26
  27: 27
  28: 28
  29: 29
  30: 30
  31: 31
  32: 32
  33: 33
  34: 34
  35: 35
  36: 36
  37: 37
  38: 38
  39: 39
  40: 40
  41: 41
  42: 42
  43: 43
  44: 44
  45: 45
  46: 46
  47: 47
  48: 48
  49: 49
  50: 50
  51: 51
  52: 52
  53: 53
  54: 54
  55: 55
  56: 56
  57: 57
  58: 58
  59: 59
  60: 60
  61: 61
  62: 62
  63: 63
  64: 64
  65: 65
  66: 66
  67: 67
  68: 68
  69: 69
  70: 70
  71: 71
  72: 72
  73: 73
  74: 74
  75: 75
  76: 76
  77: 77
  78: 78
  79: 79
  80: 80
  81: 81
  82: 82
  83: 83
  84: 84
  85: 85
  86: 86
  87: 87
  88: 88
entities:
- uid: 123
  components:
  - type: MetaData
  - type: Transform
  - type: Map
  - type: EntitySaveTest
    id: map
- uid: 0
  components:
  - type: MetaData
  - parent: 123
    type: Transform
  - chunks:
      -1,-1:
        ind: -1,-1
        tiles: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
    type: MapGrid
  - type: Broadphase
  - angularDamping: 0.05
    linearDamping: 0.05
    fixedRotation: False
    bodyType: Dynamic
    type: Physics
  - fixtures: {}
    type: Fixtures
  - type: OccluderTree
  - id: grid
    type: EntitySaveTest
- uid: 1
  type: V3TestProto
  components:
  - pos: 0.5,0.5
    parent: 0
    type: Transform
  - id: ent
    type: EntitySaveTest
...
";

    private const string PrototypeV3 = @"
- type: entity
  id: V3TestProto
  components:
  - type: EntitySaveTest
    list: [ 1, 2 ]
";
}
