#nullable enable
using System;
using System.Collections.Generic;

namespace IGP.UnitySDK.GameKit
{
    [Serializable]
    public sealed class IGPVoiceSpeakingEvent
    {
        public string RoomId { get; }
        public string PlayerId { get; }
        public string VoiceActivityId { get; }
        public long OccurredAtUnixMs { get; }

        internal IGPVoiceSpeakingEvent(
            string roomId,
            string playerId,
            string voiceActivityId,
            long occurredAtUnixMs)
        {
            RoomId = roomId ?? string.Empty;
            PlayerId = playerId ?? string.Empty;
            VoiceActivityId = voiceActivityId ?? string.Empty;
            OccurredAtUnixMs = occurredAtUnixMs;
        }
    }

    [Serializable]
    public sealed class IGPCommunicationMessageEvent
    {
        public string MessageId { get; }
        public string RoomId { get; }
        public string SenderPlayerId { get; }
        public long SentAtUnixMs { get; }
        public IReadOnlyList<IGPCommunicationSegment> Segments { get; }

        internal IGPCommunicationMessageEvent(
            string messageId,
            string roomId,
            string senderPlayerId,
            long sentAtUnixMs,
            IReadOnlyList<IGPCommunicationSegment> segments)
        {
            MessageId = messageId ?? string.Empty;
            RoomId = roomId ?? string.Empty;
            SenderPlayerId = senderPlayerId ?? string.Empty;
            SentAtUnixMs = sentAtUnixMs;

            var copy = new IGPCommunicationSegment[segments.Count];
            for (var index = 0; index < segments.Count; index++)
            {
                copy[index] = segments[index];
            }
            Segments = Array.AsReadOnly(copy);
        }
    }

    [Serializable]
    public abstract class IGPCommunicationSegment
    {
        internal IGPCommunicationSegment()
        {
        }
    }

    [Serializable]
    public sealed class IGPCommunicationTextSegment : IGPCommunicationSegment
    {
        public string Text { get; }

        internal IGPCommunicationTextSegment(string text)
        {
            Text = text ?? string.Empty;
        }
    }

    [Serializable]
    public sealed class IGPCommunicationEmotionSegment : IGPCommunicationSegment
    {
        public string EmotionId { get; }

        internal IGPCommunicationEmotionSegment(string emotionId)
        {
            EmotionId = emotionId ?? string.Empty;
        }
    }
}
