﻿
namespace Unity.Muninn.Model
{
    public enum StickyEventScope
    {
        Room,
        Player
    }

    public class StickyEventScopeConvertor
    {
        public static Unity.Muninn.Message.StickyEventScope convert(StickyEventScope scope)
        {
            switch (scope)
            {
                case StickyEventScope.Player:
                    return Unity.Muninn.Message.StickyEventScope.PlayerScope;
                case StickyEventScope.Room:
                    return Unity.Muninn.Message.StickyEventScope.RoomScope;
                default:
                    return Unity.Muninn.Message.StickyEventScope.RoomScope;
            }
        }

        public static Unity.Muninn.Model.StickyEventScope convert(Unity.Muninn.Message.StickyEventScope scope)
        {
            switch (scope)
            {
                case Unity.Muninn.Message.StickyEventScope.PlayerScope:
                    return Unity.Muninn.Model.StickyEventScope.Player;
                case Unity.Muninn.Message.StickyEventScope.RoomScope:
                    return Unity.Muninn.Model.StickyEventScope.Room;
                default:
                    return Unity.Muninn.Model.StickyEventScope.Room;
            }
        }

    }

    public class StickyEvent
    {
        public uint Tick { get; set; } // current timestamp - room.startTimeStamp
        public byte[] Data { get; set; }
        public uint SenderId { get; set; }

        public string Key { get; set; }

        public StickyEventScope Scope { get; set; }

        public static StickyEvent toModel(Unity.Muninn.Message.StickyMessage stickyMessage)
        {                
            StickyEvent res = new StickyEvent();
            res.SenderId = stickyMessage.SenderId;
            res.Data = stickyMessage.Data.ToByteArray();
            res.Key = stickyMessage.Key;
            res.Tick = stickyMessage.Tick;
            res.Scope = StickyEventScopeConvertor.convert(stickyMessage.Scope);
            return res;
        }
        
    }
}