using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.IO;

/// <summary>
/// Represents a collection of grid settings
/// </summary>
[Serializable]
public class GridSettingsCollection
{
    private int _pageSize;
    private object[] _groupByExpressionsStates;
    private object _sortExpressionsState;
    private string _filterExpression;
    private List<ColumnSettings> _columnSettings;
    private List<ColumnSettings> _autoColumnSettings;

    public int PageSize
    {
        get { return _pageSize; }
        set { _pageSize = value; }
    }

    public object[] GroupByExpressionsStates
    {
        get { return _groupByExpressionsStates; }
        set { _groupByExpressionsStates = value; }
    }

    public object SortExpressionsState
    {
        get { return _sortExpressionsState; }
        set { _sortExpressionsState = value; }
    }

    public string FilterExpression
    {
        get { return _filterExpression; }
        set { _filterExpression = value; }
    }

    public List<ColumnSettings> ColumnSettings
    {
        get { return _columnSettings; }
        set { _columnSettings = value; }
    }

    public List<ColumnSettings> AutoGeneratedColumnSettings
    {
        get { return _autoColumnSettings; }
        set { _autoColumnSettings = value; }
    }

    /// <summary>
    /// Returns the serialized object as string
    /// </summary>
    public override string ToString()
    {
        LosFormatter formatter = new LosFormatter();
        using (StringWriter writer = new StringWriter())
        {
            formatter.Serialize(writer, this);
            return writer.ToString();
        }
    }

    /// <summary>
    /// Returns the serialized object as byte array
    /// </summary>
    public byte[] ToArray()
    {
        LosFormatter formatter = new LosFormatter();
        using (MemoryStream stream = new MemoryStream())
        {
            formatter.Serialize(stream, this);
            return stream.ToArray();
        }
    }

    /// <summary>
    /// Gets the GridSettingsCollectionInstance from its serialized string data
    /// </summary>
    /// <param name="data">The object as serialized string data</param>
    public static GridSettingsCollection LoadFromSerializedData(string data)
    {
        LosFormatter formatter = new LosFormatter();
        return (GridSettingsCollection)formatter.Deserialize(data);
    }

    /// <summary>
    /// Gets the GridSettingsCollectionInstance from its serialized byte array
    /// </summary>
    /// <param name="data">The object as serialized byte array</param>
    public static GridSettingsCollection LoadFromSerializedData(byte[] data)
    {
        LosFormatter formatter = new LosFormatter();
        using (MemoryStream stream = new MemoryStream(data))
        {
            return (GridSettingsCollection)formatter.Deserialize(stream);
        }
    }
}