﻿namespace Yodo1.FanCraft
{
    using System.Collections.Generic;

    public class NotificationReward
    {
        public string RewardId { get; private set; }
        public int Quantity { get; private set; }

        public NotificationReward(Dictionary<string, object> dict)
        {
            if (dict.ContainsKey("reward_id"))
            {
                RewardId = dict["reward_id"].ToString();
            }
            if (dict.ContainsKey("quantity"))
            {
                Quantity = int.Parse(dict["quantity"].ToString());
            }
        }
    }

    public class InterstialNotificationHandler
    {
        public FanCraftSDK.InterstialNotificationEvent NotificationEvent { get; private set; }
        public FanCraftSDK.NotificationType NotificationType { get; private set; }
        public FanCraftSDK.NotificationActionType NotificationActionType { get; private set; }
        public string NotificationActionUrl { get; private set; }
        public List<NotificationReward> Rewards { get; private set; }

        public InterstialNotificationHandler(Dictionary<string, object> dict)
        {
            int notificationE = -1;
            if (dict.ContainsKey("notification_event"))
            {
                notificationE = int.Parse(dict["notification_event"].ToString());
            }
            NotificationEvent = (FanCraftSDK.InterstialNotificationEvent)notificationE;

            int type = -1;
            if (dict.ContainsKey("notification_type"))
            {
                type = int.Parse(dict["notification_type"].ToString());
            }
            NotificationType = (FanCraftSDK.NotificationType)type;


            int actionType = -1;
            if (dict.ContainsKey("notification_action_type"))
            {
                actionType = int.Parse(dict["notification_action_type"].ToString());
            }
            NotificationActionType = (FanCraftSDK.NotificationActionType)actionType;

            if (dict.ContainsKey("notification_action_url"))
            {
                NotificationActionUrl = dict["notification_action_url"].ToString();
            }

            Rewards = new List<NotificationReward>();
            if (dict.ContainsKey("notification_rewards"))
            {
                List<object> rewardsList = (List<object>)dict["notification_rewards"];
                for (int i = 0; i < rewardsList.Count; i++)
                {
                    Dictionary<string, object> rewardDict = (Dictionary<string, object>)rewardsList[i];

                    NotificationReward reward = new NotificationReward(rewardDict);
                    Rewards.Add(reward);
                }
            }
        }

        public FanCraftSDK.InterstialNotificationEvent GetNotificationEvent()
        {
            return NotificationEvent;
        }

        public FanCraftSDK.NotificationType GetNotificationType()
        {
            return NotificationType;
        }

        public FanCraftSDK.NotificationActionType GetAction()
        {
            return NotificationActionType;
        }

        public string GetActionURL()
        {
            return NotificationActionUrl;
        }

        public List<NotificationReward> GetRewards()
        {
            return Rewards;
        }
    }
}
