using Foresight.Fleet.Services.Customer;
using Foresight.Fleet.Services.User;
using IronIntel.Contractor.Users;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IronIntel.Contractor.Site.Credentials
{
    public class CredentialsBasePage : ContractorBasePage
    {
        protected void ProcessRequest(string methodName)
        {
            object result = null;

            if (methodName != null)
            {
                switch (methodName.ToUpper())
                {
                    case "GETNAVS":
                        result = GetNavigations();
                        break;
                }
            }

            string json = JsonConvert.SerializeObject(result);
            Response.Write(json);
            Response.End();
        }
        private CredentialNavigateItem[] GetNavigations()
        {
            List<CredentialNavigateItem> list = GetNavigateItems();
            LicenseInfo license = SystemParams.GetLicense();
            if (license != null && license.Items.Count > 0)
            {
                var jdn = license.Items.FirstOrDefault(m => m.Key == "JohnDeereNotifications");
                if (jdn == null || !Helper.IsTrue(jdn.Value))
                {
                    CredentialNavigateItem item = list.FirstOrDefault(m => m.ID == "nav_jdnotification");
                    list.Remove(item);
                }
            }
            return list.ToArray();
        }


        public static List<CredentialNavigateItem> GetNavigateItems()
        {
            List<CredentialNavigateItem> list = new List<CredentialNavigateItem>();

            CredentialNavigateItem item1 = new CredentialNavigateItem();
            item1.ID = "nav_credential";
            item1.Title = "Credentials";
            item1.Url = "ManageCredential.aspx";
            item1.IconPath = "img/credential.png";
            list.Add(item1);

            CredentialNavigateItem item2 = new CredentialNavigateItem();
            item2.ID = "nav_jdlink";
            item2.Title = "JD Link";
            item2.Url = "ManageJDLink.aspx";
            item2.IconPath = "img/jdlink.png";
            list.Add(item2);

            //CredentialNavigateItem item3 = new CredentialNavigateItem();
            //item3.ID = "nav_jdnotification";
            //item3.Title = "JohnDeere Notifications";
            //item3.Url = "ManageJDNotifications.aspx";
            //item3.IconPath = "img/jdnotifications.png";
            //list.Add(item3);

            CredentialNavigateItem item4 = new CredentialNavigateItem();
            item4.ID = "nav_apicredential";
            item4.Title = "API Credentials";
            item4.Url = "ManageAPICredential.aspx";
            item4.IconPath = "img/apicredential.png";
            list.Add(item4);
            return list;
        }
    }
}
