﻿using System;
using SimpleJSON;

namespace ChatSDK {

    /**
     * The class for read receipts of group messages.
     * 
     */
    public class GroupReadAck
    {
        /**
         * The ID of the read receipt of a group message.
         */
        public string AckId { get; internal set; }

        /**
         * The ID of the group message.
         */
        public string MsgId { get; internal set; }

        /**
         * The ID of the user who sends the read receipt.
         */
        public string From { get; internal set; }

        /**
         * The extension information of a read receipt.
         * 
         * The read receipt extension is passed as the third parameter in ({@link XXX}) that is the method of sending the read receipt.
         */
        public string Content { get; internal set; }

        /**
         * The number of read receipts that are sent for group messages.
         */
        public int Count { get; internal set; }

        /**
         * The Unix timestamp of sending the read receipt of a group message.
         */
        public long Timestamp { get; internal set; }

        internal GroupReadAck(string jsonString) {
            if (jsonString != null) {
                JSONNode jn = JSON.Parse(jsonString);
                if (!jn.IsNull && jn.IsObject)
                {
                    JSONObject jo = jn.AsObject;
                    AckId = jo["ackId"].Value;
                    MsgId = jo["msgId"].Value;
                    From = jo["from"].Value;
                    Content = jo["content"].Value;
                    Count = jo["count"].AsInt;
                    Timestamp = jo["timestamp"].AsInt;
                }
            }
        }

        internal GroupReadAck()
        {

        }
    }
}

