﻿using System.Runtime.InteropServices;
using SimpleJSON;

namespace ChatSDK
{

    /**
     * The shared file information class, which defines how to manage shared files.
     * 
     * For example, you can get information about a group shared file by using {@link IGroupManager#GetGroupFileListFromServer(String, int, int, ValueCallBack)}.
     * 
     */
    [StructLayout(LayoutKind.Sequential)]
    public class GroupSharedFile
    {
        /**
         * The name of the shared file.
         */
        public string FileName { get; internal set; }

        /**
         * The ID of the shared file.
         */
        public string FileId { get; internal set; }

        /**
         * The user ID of the member who uploads the shared file.
         */
        public string FileOwner { get; internal set; }

        /**
         * The Unix timestamp for updating the shared file. The unit is millisecond.
         */
        public long CreateTime { get; internal set; }

        /**
         * The size of the shared file, in bytes.
         */
        public long FileSize { get; internal set; }

        internal GroupSharedFile(string jsonString)
        {
            if (jsonString != null) {
                JSONNode jn = JSON.Parse(jsonString);
                if (!jn.IsNull && jn.IsObject)
                {
                    JSONObject jo = jn.AsObject;
                    FileName = jo["name"].Value;
                    FileId = jo["fileId"].Value;
                    FileOwner = jo["owner"].Value;
                    CreateTime = jo["createTime"].AsInt;
                    FileSize = jo["fileSize"].AsInt;
                }
            }            
        }

        internal GroupSharedFile()
        {

        }
    }

}
