using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IOB_UT_NEXT
{
    /// <summary>
    /// Classe per gestione Job Task2Exe x una macchina
    /// </summary>
    public class JobTaskData
    {
        #region Public Constructors

        public JobTaskData(string codTav, string rawData)
        {
            CodTav = codTav;
            RawData = rawData;
        }

        #endregion Public Constructors

#if false
        public JobTaskData(string codTav, Dictionary<string, string> newDict)
        {
            CodTav = codTav;
            RawData = JsonConvert.SerializeObject(newDict);
        }
#endif

        #region Public Properties

        /// <summary>
        /// Codice tavola (empty = main)
        /// </summary>
        public string CodTav { get; private set; } = "";

        /// <summary>
        /// Dizionario in formato raw (da deserializzare
        /// </summary>
        public string RawData { get; private set; } = "";

        #endregion Public Properties

        #region Public Methods

        /// <summary>
        /// Dizionario dei Task associati
        /// </summary>
        public static Dictionary<string, string> TaskDict(string rawData)
        {
            var answ = new Dictionary<string, string>();
            if (!string.IsNullOrEmpty(rawData))
            {
                answ = JsonConvert.DeserializeObject<Dictionary<string, string>>(rawData) ?? new Dictionary<string, string>();
            }
            return answ;
        }

        #endregion Public Methods
    }
}