﻿using System.Collections.Generic;
using SimpleJSON;

namespace ChatSDK
{

    /**
     * The presence device status class
     */
    public class PresenceDeviceStatus
    {
        /**
         * The presence device Id.
         */
        public string DeviceId;


        /**
         * The presence device status
         */
        public int Status;

        internal PresenceDeviceStatus()
        {
           
        }

        internal PresenceDeviceStatus(JSONObject json) {
            foreach (string key in json.Keys) {
                DeviceId = key;
                Status = json[key].AsInt;
            }
        }
    }

    /**
     * The presence property class that contains presence properties, including the publisher's user ID and current presence state, and the platform used by the online device, as well as the presence's extension information, update time, and subscription expiration time.
     */

    public class Presence
    {
        /**
         * Gets the user ID of the presence publisher.
         *
         * @return The user ID of the presence publisher.
         */

        public string Publisher { get; internal set; }

        /**
         * Gets the details of the current presence state. The presence state details are a key-value structure, where the key can be "ios", "android", "linux", "windows", or "webim", and the value is the current presence state of the publisher.
         *
         * @return The details of the current presence state.
         */

        public List<PresenceDeviceStatus> StatusList { get; internal set; }


        /**
         * Gets the presence status description information.
         *
         * @return The presence status description information.
         */

        public string statusDescription { get; internal set; }

        /**
         * Gets the presence update time.
         *
         *  @return The Unix timestamp when the presence state is updated. The unit is second.
         */
        public long LatestTime { get; internal set; }

        /**
         * Gets the expiration time of the presence subscription.
         *
         * @return  The Unix timestamp when the presence subscription expires. The unit is second.
         */

        public long ExpiryTime { get; internal set; }

        internal Presence()
        {
            // Default constructor, No need to add any code
        }

        internal Presence(JSONObject json)
        {
            Publisher = json["publisher"].Value;
            statusDescription = json["statusDescription"].Value;
            LatestTime = json["lastTime"].AsInt;
            ExpiryTime = json["expiryTime"].AsInt;
            StatusList = new List<PresenceDeviceStatus>();
            if (json["statusDetails"].IsArray) {
                JSONArray ary = json["statusDetails"].AsArray;
                foreach (JSONObject jo in ary) {
                    StatusList.Add(new PresenceDeviceStatus(jo));
                }
            }
        }

    }
}
