using System;
using GameData;
using Server.Core;

namespace Server.AliyunSDK.SLSLog
{
    public class EventTrackData
    {
        public double Item_Number;
        public string Item_String;
    }
    
    /// <summary>
    /// 事件统计数据
    /// </summary>
    public class StatisticsTrackingLogData : SLSLogData
    {
        public string EventData;
        public string EventId;
        [SLSLogTimeFormat("yyyy-MM-dd HH:mm:ss")]
        public DateTime EventTime;
        public EventTrackerType EventType;
        public string Identifier;
        public string Platform;
        
        [SLSIgnore]
        public double NumberCount;
        [SLSIgnore]
        public string ItemString;
        [SLSIgnore]
        public DateTime GroupTime;

        public static StatisticsTrackingLogData CreateNumber(string identifier, string eventId, double itemCount, string platform)
        {
            var data = Create(identifier, eventId, itemCount, "", platform);
            data.EventType = EventTrackerType.Number;
            return data;
        }
        
        public static StatisticsTrackingLogData CreateString(string identifier, string eventId, string itemString, string platform)
        {
            var data = Create(identifier, eventId, 1, itemString, platform);
            data.EventType = EventTrackerType.String;
            return data;
        }
        
        public static StatisticsTrackingLogData Create(string identifier, string eventId, double itemCount, string itemString, string platform = "")
        {
            StatisticsTrackingLogData data = ReferencePool.Fetch<StatisticsTrackingLogData>();
            data.Identifier = identifier;
            data.Platform = platform;
            data.EventId = $"{eventId}.{EventTrackerCategory.Server}";
            data.EventData = JsonPack.GetJson(new EventTrackData()
            {
                Item_Number = itemCount,
                Item_String = itemString
            });
            data.EventTime = DateTime.Now;
            data.EventType = EventTrackerType.Param;
            data.Time = DateTimeOffset.Now;
            return data;
        }
    }
}