using System;
using System.Collections.Generic;
using System.Text;

namespace OnlineUserPool.Model
{
    public class TargetData
    {
        public double _Power = 0d;
        public double _Speed = 0;
        public double _Distance = 0D;
        public double? _Cadence = 0;
        public int? _HeartRate = 0;
        public int Ticks = 0;
        /// <summary>
        /// 纬度
        /// </summary>
        public double _Lat = 0d;
        /// <summary>
        /// 经度
        /// </summary>
        public double _Lon = 0d;
        public double _Bearing = 0d;

        public TargetData Clone()
        {
            return (TargetData)MemberwiseClone();
        }

        public override string ToString()
        {
            return string.Format($"Ticks:{Ticks} Power:{_Power} Speed:{_Speed} Distance:{_Distance} Cadence:{_Cadence} HeartRate:{_HeartRate} Lat:{_Lat} Lon:{_Lon}");
        }

        public string Write()
        {
            return string.Format($"{Ticks},{_Power},{_Speed},{_Distance},{_Cadence},{_HeartRate},{_Lat},{_Lon},{_Bearing}");
        }

        public static TargetData Read(string data)
        {
            string[] split = data.Split(',');
            var target = new TargetData();
            target.Ticks = int.Parse(split[0]);
            target._Power = double.Parse(split[1]);
            target._Speed = double.Parse(split[2]);
            target._Distance = double.Parse(split[3]);
            target._Cadence = double.Parse(split[4]);
            target._HeartRate = int.Parse(split[5]);
            if (split.Length > 6)
            {
                target._Lat = double.Parse(split[6]);
                target._Lon = double.Parse(split[7]);
                target._Bearing = double.Parse(split[8]);
            }
            return target;
        }
    }
}
