using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AX.Serialization;
using MessagePack;

#pragma warning disable 0219
public class SerializationTest : MonoBehaviour
{
    [MessagePackObject]
    public class Foo
    {
        [Key(0)]
        public Vector3 Position = Vector3.one;
        [Key(1)]
        public int A = 1;
        [Key(2)]
        public object Command;
        [Key(3)]
        public object CmdArgs;
    }

    [MessagePackObject]
    public class Bar : Foo
    {
        [Key(4)]
        public int B = 2;
    }

    [MessagePackObject]
    public class Command { }
    [MessagePackObject]
    public class CmdArgs { }
    [MessagePackObject]
    public class CommandA : Command { [Key(0)]public string Name = "CommandA"; }
    [MessagePackObject]
    public class CmdArgsA : CmdArgs { [Key(0)]public string Name = "CmdArgsA"; }

    void Start()
    {
        Foo foo = new Bar();
        Bar bar = new Bar();

        var bytes1 = foo.Serialize();
        var json1 = Serializer.ToJson(bytes1.Array);
        var target1 = bytes1.Deserialize<Foo>() as Bar;

        var bytes2 = bar.Serialize();
        var json2 = Serializer.ToJson(bytes2.Array);
        var target2 = bytes2.Deserialize<Bar>();

        var bytes3 = foo.TypelessSerialize();
        var json3 = Serializer.ToJson(bytes3);
        var target3 = bytes3.TypelessDeserialize();
        var target4 = target3 as Foo;
        var target5 = target3 as Bar;

        var bytes4 = foo.CompressedSerialize();
        var json4 = Serializer.CompressedToJson(bytes4);
        var target6 = bytes4.CompressedDeserialize<Foo>();

        var bytes5 = foo.CompressedTypelessSerialize();
        var json5 = Serializer.CompressedToJson(bytes5);
        var target7 = bytes5.CompressedTypelessDeserialize();
        var target8 = target7 as Foo;
        var target9 = target7 as Bar;

        var complex = new Foo();

        complex.Command = new CommandA();
        complex.CmdArgs = new CmdArgsA();

        var bytes6 = complex.TypelessSerialize();
        var json6 = Serializer.ToJson(bytes6);
        var target10 = bytes6.TypelessDeserialize() as Foo;
    }
}
#pragma warning restore 0219