using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
namespace Ips.Library.Entity
{
    public class GeoLLA
    {
        public GeoLLA() : this(LonNan.Value, LatNan.Value, 0) { }
        public GeoLLA(double lon, double lat) : this(lon, lat, 0) { }
        public GeoLLA(double lon, double lat, double alt)
        {
            Lon = lon;
            Lat = lat;
            Alt = alt;
        }
        /// 
        /// 经度
        /// 
        public double Lon { get; set; }
        /// 
        /// 纬度
        /// 
        public double Lat { get; set; }
        /// 
        /// 高度
        /// 
        public double Alt { get; set; }
        public const double MinLon = -180;
        public const double MaxLon = 180;
        public const double MinLat = -90;
        public const double MaxLat = 90;
        public override string ToString()
        {
            return $"{Lon},{Lat},{Alt}";
        }
        public bool IsSome(GeoLLA item)
        {
            if (item == null) return false;
            if (ReferenceEquals(this, item)) return true;
            return Lon == item.Lon && Lat == item.Lat && Alt == item.Alt;
        }
        public bool IsValid()
        {
            return Lon >= MinLon && Lon <= MaxLon && Lat >= MinLat && Lat <= MaxLat;
        }
        public double[] ToArray()
        {
            return new double[] { Lon, Lat, Alt };
        }
        public static GeoLLA FromString(string val, string itemsep = ",")
        {
            var items = val.Split(itemsep.ToCharArray());
            double lon = LonNan.Value, lat = LatNan.Value, alt = 0;
            if (items.Length > 1)
            {
                lon = double.Parse(items[0].Trim());
                lat = double.Parse(items[1].Trim());
            }
            if (items.Length > 2)
            {
                alt = double.Parse(items[2].Trim());
            }
            return new GeoLLA(lon, lat, alt);
        }
    }
    public class LonNan
    {
        public const double Value = 181;
    }
    public class LatNan
    {
        public const double Value = 91;
    }
}