﻿namespace Stove.StoveSDK
{
    using System.Collections.Generic;
    using MiniJSON;

    /**
     * Log Event.
     * @param name Unique value to distinguish between events.
     * @param category1 1's depth category.
     * @param category2 2's depth category.
     * @param simpleValue If you enter that value, it will be displayed numerically when displayed in xk5 Analytics.
     * @param parameters Additional parameters of the event.
     * @since 2.0.0
     */
    public class LogEvent
    {
        /**
         * Unique value to distinguish between events.
         * @since 2.0.0
         */
        public string Name { get; }

        /**
         * 1's depth category.
         * @since 2.0.0
         */
        public string Category1 { get; set; }

        /**
         * 2's depth category.
         * @since 2.0.0
         */
        public string Category2 { get; set; }

        /**
         * If you enter that value, it will be displayed numerically when displayed in xk5 Analytics.
         * @since 2.0.0
         */
        public float? SimpleValue { get; set; }

        /**
         * Additional parameters of the event.
         * @since 2.0.0
         */
        public Dictionary<string, string> Parameters { get; set; }

        public LogEvent(string name)
        {
            Name = name;
            Category1 = null;
            Category2 = null;
            SimpleValue = null;
            Parameters = null;
        }

        public LogEvent(string name, string category1, string category2, float? simpleValue, Dictionary<string, string> parameters)
        {
            Name = name;
            Category1 = category1;
            Category2 = category2;
            SimpleValue = simpleValue;
            Parameters = parameters;
        }

        /**
         * Dictionary deserialization.
         * @since 2.0.0
         */
        public Dictionary<string, object> ToDictionary()
        {
            Dictionary<string, object> dictionary = new Dictionary<string, object>();
            dictionary.Add("name", Name);
            if(Category1 != null)
            {
                dictionary.Add("category1", Category1);
            }
            if (Category2 != null)
            {
                dictionary.Add("category2", Category2);
            }
            if (SimpleValue != null)
            {
                dictionary.Add("simpleValue", SimpleValue);
            }
            if (Parameters != null)
            {
                dictionary.Add("parameters", Parameters);
            }
            return dictionary;
        }

        /**
         * JSON serialization.
         * @since 2.0.0
         */
        public string ToJSONString()
        {
            Dictionary<string, object> dictionary = ToDictionary();
        
            return Json.Serialize(dictionary);
        }

        public override string ToString()
        {
            return "LogEvent(Name='" + Name + "', Category1=" + Category1 + ", Category2='" + Category2 + "', SimpleValue=" + SimpleValue + ", Parameters='" + Parameters + ")";
        }
    }
}

