using Newtonsoft.Json;
using System;
using System.Security.Principal;

namespace UtilLib
{
    public class UpgradeSource
    {
        public int Code { get; set; }
        [JsonProperty("msg")]
        public string Message { get; set; }
        public UpgradeData Data { get; set; }
    }

    public class UpgradeData
    {
        public int Id { get; set; }
        /// <summary>
        /// APP名称
        /// </summary>
        [JsonProperty("app_name")]
        public string AppName { get; set; }
        /// <summary>
        /// 客户端类型 1ios 2安卓 3window插件 4 5
        /// </summary>
        [JsonProperty("client_type")]
        public int ClientType { get; set; }
        /// <summary>
        /// 发布类型
        /// </summary>
        [JsonProperty("publish_type")]
        public int PublishType { get; set; }
        /// <summary>
        /// 发布的版本号
        /// </summary>
        public string Version { get; set; }
        /// <summary>
        /// 升级类型（1强制升级 2强制提示 3弱提示）
        /// </summary>
        [JsonProperty("upgrade_type")]
        public int UpgradeType { get; set; }
        [JsonProperty("download_url")]
        public string DownloadUrl { get; set; }
        /// <summary>
        /// 发布时间
        /// </summary>
        [JsonProperty("publish_time")]
        public int PublishTime { get; set; }
        /// <summary>
        /// 发布的信息
        /// </summary>
        public string Message { get; set; }
        [JsonProperty("compatible_version_id")]
        public int CompatibleVersionId { get; set; }
        [JsonProperty("is_show_pop")]
        public int IsShowPop { get; set; }

        public int Ext { get; set; }

        public bool NeedUpgrade(string currentVersion)
        {
            var remoteVer = new Version(Version);
            var currentVer = new Version(currentVersion);
            return remoteVer > currentVer;
        }
    }
}
