using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web;

namespace FinancialChartExplorer.Models
{
    public static class BoxData
    {
        private static List<FinanceData> _jsonData;
        public static List<FinanceData> GetDataFromJson()
        {
            if (_jsonData != null)
            {
                return _jsonData;
            }

            string path = HttpContext.Current.Server.MapPath("~/Content/box.json");
            string jsonText = new StreamReader(path, System.Text.Encoding.Default).ReadToEnd();
            JArray ja = (JArray)JsonConvert.DeserializeObject(jsonText);
            List<FinanceData> list = new List<FinanceData>();
            foreach (var obj in ja)
            {
                string date = obj["date"].ToString();
                double high = Convert.ToDouble(obj["high"].ToString());
                double low = Convert.ToDouble(obj["low"].ToString());
                double open = Convert.ToDouble(obj["open"].ToString());
                double close = Convert.ToDouble(obj["close"].ToString());
                double volume = Convert.ToDouble(obj["volume"].ToString());
                list.Add(new FinanceData { X = date, High = high, Low = low, Open = open, Close = close, Volume = volume });
            }
            _jsonData = list;
            return list;
        }

        private static List<string> _annotationToolTips;
        public static List<string> GetAnnotationTooltips()
        {
            if (_annotationToolTips != null)
            {
                return _annotationToolTips;
            }
            _annotationToolTips = new List<string>{
         "<b>Why the hot IPO market is cooling off?</b>",
         "<b>Tech IPO market healthy?</b>",
         "<b>Center for Sustainable Energy Leverages Box to Power California Clean Vehicle Rebate Project</b>"
         +"<br>Box today announced that the Center for Sustainable Energy, a nonprofit organization committed to accelerating the transition to a sustainable world powered by clean energy, is leveraging the Box platform to power a cloud-based document submission and review process as part of the Clean Vehicle Rebate Project.",
         "<b>Box to Present at the J.P. Morgan Technology, Media and Telecom Conference</b>"+
         "<br>Box today announced that Aaron Levie, co-founder and CEO, will participate in the J.P. Morgan Technology, Media and Telecom Conference in Boston on Monday, May 18, 2015.",
         "<b>BD Receives FDA Clearance for a Novel Infusion Set with BD FlowSmart™ Technology to Enhance the Use of Insulin Pumps</b>"+
         "<br>Unique Side-Ported Catheter Designed to Offer Consistent Insulin Delivery and Fewer Flow Interruptions including Silent Occlusions Infusion Set Developed in Collaboration with JDRF and Helmsley Charitable ...",
         "<b>Wall Street tech debutant Box dismisses doubters</b>",
         "<b>BD Board Declares Dividend</b>"+
         "<br>The Board of Directors of BD (Becton, Dickinson and Company) (NYSE: BDX) has declared a quarterly dividend of 60.0 cents per common share payable on June ...",
         "<b>Box Sets Date to Announce First Quarter Fiscal 2016 Financial Results</b>"+
         "<br>Box today announced that it will report financial results for its first quarter which ended April 30, 2015, following the close of the market on Wednesday, June 10, 2015.",
         "<b>Making Money With Charles Payne: 05/21/15</b>",
         "<b>Best Buy to move sideways: Analyst</b>",
         "<b>Macquarie Upgrades Hercules Technology, Likes Dividend</b>"+
         "<br>In a report published Tuesday, Macquarie analysts upgraded their rating on Hercules Technology Growth Capital, Inc. (NYSE: HTGX), with a price target of $14. The analysts believe that the company's dividend ...",
         "<b>The U.S. Department of Justice Selects Box to Enable Enterprise File Sharing</b>"+
         "<br>Box today announced that it is working with the U.S. Department of Justice to deliver file sharing and information management to the agency’s workforce. After rigorous assessment, Box will receive an agency Authorization to Operate this week, allowing the DOJ to leverage the platform across all its component agencies.",
         "<b>Box Enables Improved Collaboration and Content Sharing at the ASPCA</b>"+
         "<br>Box today announced that the ASPCA® , the first humane society established in North America, is bringing Box’s cloud content sharing and collaboration platform to its employees."
         };

            return _annotationToolTips;
        }
    }
}