using GrapeCity.ActiveReports.Web.Designer;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using GrapeCity.ActiveReports.PageReportModel;
using System;
namespace WebDesigner_CustomSharedDataSources.Implementation
{
    public static class DataSetTemplatesStore
    {
        public static Stream GetDataSet(string id)
        {
            Items.TryGetValue(id, out DataSetTemplate dataSet);
            return dataSet.ToJsonStream();
        }

        public static ResourceDescriptor[] GetDataSetsList()
        {
            return DataSetTemplatesStore.Items
                .Select(i => new ResourceDescriptor
                {
                    Id = i.Key,
                    Name = i.Key,
                })
                .ToArray();
        }

        private static IDictionary<string, DataSetTemplate> Items { get; }

        static DataSetTemplatesStore()
        {
            var items = new Dictionary<string, DataSetTemplate>();
            items.Add("BalanceSheetDataSet", new DataSetTemplate
            {
                DataSource = new DataSource
                {
                    Name = "BalanceSheetDataSource",
                    DataSourceReference = "BalanceSheet.rdsx"
                },
                DataSet = new DataSet
                {
                    Name = "BalanceSheetDataSet",
                    Query = {
                        CommandText = "Select * from BalanceSheet",
                        DataSourceName = "BalanceSheetDataSource"
                    },
                    Fields = {
                        new Field {
                            Name = "TotalAssets",
                            DataField = "TotalAssets"
                        }
                    }
                }
            });
            Items = items;
        }
    }
}
