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

    public class ProviderUser
    {
        /**
         * Unique value of other platform defined in stove.
         * @since 2.0.0
         */
        public int Type { get; }

        /**
         * Provider's user id
         * @since 2.0.0
         */
        public string UserId { get; }

        /**
         * Email  in case of email provider.
         * @since 2.0.0
         */
        public string Email { get; }

        /**
         * Whether the email is verified..
         * @since 2.0.0
         */
        public bool VerifiedEmail { get; }

        /**
         * Dictionary deserialization.
         * @since 2.0.0
         */
        public ProviderUser(Dictionary<string, object> dictionary)
        {
            Type = Convert.ToInt32(dictionary["type"]);
            UserId = dictionary["userId"] as string;

            if (dictionary.ContainsKey("email"))
            {
                Email = dictionary["email"] as string;
            }

            if (dictionary.ContainsKey("verifiedEmail"))
            {
                VerifiedEmail = Convert.ToBoolean(dictionary["verifiedEmail"]);
            }
        }

        /**
         * Dictionary serialization.
         * @since 2.0.0
         */
        public Dictionary<string, object> ToDictionary()
        {
            Dictionary<string, object> dictionary = new Dictionary<string, object>();
            dictionary.Add("type", Type);
            dictionary.Add("userId", UserId);

            if (Email != null)
            {
                dictionary.Add("email", Email);
            }

            dictionary.Add("verifiedEmail", VerifiedEmail);
              
            return dictionary;
        }

        public override string ToString()
        {
            return "ProviderUser(Type='" + Type
                + "', UserId='" + UserId
                + "', Email=" + Email
                + "', VerifiedEmail=" + VerifiedEmail
                + ")";
        }
    }
}
