using FreeSql.DataAnnotations;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Txgy.EWS.Client.Entity;
using Txgy.Microseismic.BaseLib.Entitys;

namespace Txgy.EWS.Client.Models
{
    public class GridItemEventResult
    {
        public bool IsSelected { get; set; } = true;
        [JsonProperty, Column(DbType = "varchar(254)")]
        public string EventTime { get; set; }
        [Column(IsIgnore = true)]
        public DateTime OTime { get; set; }
        [JsonProperty, Column(DbType = "int")]
        public int LocSta { get; set; }

        [JsonProperty]
        public double ML { get; set; }

        [JsonProperty, Column(DbType = "int")]
        public int MLSta { get; set; }

        [JsonProperty, Column(DbType = "varchar(254)")]
        public string OriginTime { get; set; }

        [JsonProperty, Column(DbType = "int")]
        public int EventID { get; set; }

        [JsonProperty]
        public double RMS { get; set; }

        [JsonProperty, Column(DbType = "int")]
        public int WorkAreaID { get; set; }

        [JsonProperty]
        public double X { get; set; }

        [JsonProperty]
        public double Y { get; set; }

        [JsonProperty]
        public double Z { get; set; }
        public double Energy { get; set; }
        /// <summary>
        /// 震源性质:1：走滑；2：剪切；3：张性；4：未识别
        /// </summary>
        public int SourceChara { get; set; }
        /// <summary>
        /// 震源机制方向
        /// </summary>
        public double Direction { get; set; }
        /// <summary>
        /// 应力降
        /// </summary>
        public double StressDrop { get; set; }
        /// <summary>
        /// 主频
        /// </summary>
        public int DominantFreq { get; set; }
        /// <summary>
        /// 矩震级
        /// </summary>
        public double MW { get; set; }
        public Dictionary<string, int> Phases { get; set; }
        public string JsonFile { get; set; }
        public void SetEnergy()
        {
            double mi = Math.Round(4.83 + 1.47 * ML, 4);
            Energy = Math.Round(Math.Pow(10,mi), 2);
        }
        public GridItemEventResult()
        {
            
        }
        public GridItemEventResult(RemoteRealtimeResultEntity re,bool transpose)
        {
            IsSelected = true;
            WorkAreaID = re.WorkAreaID;
            EventID = re.RTEventID;
            EventTime = re.EventTime;
            OTime = DateTime.Parse(EventTime);
            OriginTime = re.OriginTime;
            RMS = re.RMS;
            if (transpose)
            {
                X = re.Y;
                Y = re.X;
            }
            else
            {
                X = re.X;
                Y = re.Y;
            }
            Z = re.Z;
            ML = re.ML;
            LocSta = re.LocSta;
            MLSta = re.MLSta;
            Energy = re.Energy;
            //SetEnergy();
        }
        public GridItemEventResult(MmEventEntity mee)
        {
            IsSelected = true;
            WorkAreaID = mee.WorkAreaID;
            EventID = mee.EventID;
            EventTime = mee.EventTimeStr;
            OTime=DateTime.Parse(EventTime);
            OriginTime = mee.OriginTime;
            RMS = mee.RMS;
            X = mee.X; Y = mee.Y; Z = mee.Z;
            ML = mee.ML;
            LocSta = mee.LocSta;
            MLSta = mee.MLSta;
            Energy = mee.Energy;
            //SetEnergy();
        }

    }
}
