using System.Numerics;

namespace Edge.Core.Domain.FccStationInfo.Input
{
    public class StationInfoInput
    {
        /// <summary>
        /// id
        /// </summary>
        public long? Id { get; set; }

        /// <summary>
        /// 云端站点 id
        /// </summary>
        public string? BuildId { get; set; }

        /// <summary>
        /// 站点名称
        /// </summary>
        public string? Name { get; set; }

        /// <summary>
        /// 客户端id
        /// </summary>
        public string SecretId { get; set; }

        /// <summary>
        /// 与云端加密的 key
        /// </summary>
        public string AcessKey { get; set; }

        /// <summary>
        /// 经度
        /// </summary>
        public decimal? Longitude { get; set; }

        /// <summary>
        /// 纬度
        /// </summary>
        public decimal? Latitude { get; set; }

        /// <summary>
        /// 小程序链接地址
        /// </summary>
        public string? SmallProgram { get; set; }

        /// <summary>
        /// 云端地址
        /// </summary>
        public string? CloudService { get; set; }

        /// <summary>
        /// 云端  MQTT 地址
        /// </summary>
        public string? MqttService { get; set; }

        /// <summary>
        /// icard 数据库连接地址
        /// </summary>
        public string? IcardService { get; set; }

        /// <summary>
        /// 本地 fcc 与 fcc 页面 webSocket 端口
        /// </summary>
        public string? WebSocketPort { get; set; }

        public FccStationInfo? ToComponent()
        {
            if (IsNotNorm()) return null;

            return new FccStationInfo()
            {
                BuildId = this.BuildId,
                Name = this.Name != null ? this.Name : "",
                SecretId = this.SecretId,
                AcessKey = this.AcessKey,
                Longitude = (decimal)(this.Longitude != null ? this.Longitude : new decimal(0)),
                Latitude = (decimal)(this.Latitude != null ? this.Latitude : new decimal(0)),
                SmallProgram = this.SmallProgram,
                CloudService = this.CloudService,
                MqttService = this.MqttService,
                IcardService = this.IcardService != null ? this.IcardService : "",
                WebSocketPort = this.WebSocketPort
            };
        }

        public bool IsNotNorm()
        {
            return string.IsNullOrEmpty(BuildId) || !Longitude.HasValue || !Latitude.HasValue || string.IsNullOrEmpty(SmallProgram) || string.IsNullOrEmpty(CloudService)
                || string.IsNullOrEmpty(MqttService) || string.IsNullOrEmpty(WebSocketPort);
        }
    }
}
