using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vrh.OneReport.Lib.Areas.OneReport.Models
{
    /// <summary>
    /// Holds the list of a menu items for a user role.
    /// </summary>
    public class UserRoleGroupModel
    {
        public enum ItemGroupState
        {
            Unknown,
            Opened,
            Closed
        }

        public string Name { get; set; }

        public List<ItemDescriptor> Items { get; set; }

        public ItemGroupState GroupState { get; set; }
    }

    /// <summary>
    /// Holds the query and report data needed for a menu item.
    /// </summary>
    public class ItemDescriptor
    {
        public string Name { get; set; }

        public string Controller { get; set; }

        public string Action { get; set; }

        public object Params { get; set; }

        public string Description { get; set; }
    }

    /// <summary>
    /// Holds the data needed for a database command parameter.
    /// </summary>
    public class CommandParameter
    {
        public static int CommandTimeout
        {
            get
            {
                string value = System.Web.Configuration.WebConfigurationManager.AppSettings.Get("SQLCommandTimeout");
                int timeout;

                return (string.IsNullOrEmpty(value) || !int.TryParse(value, out timeout) ? -1 : timeout);
            }
        }
        /// <summary>
        /// Name of the parameter.
        /// </summary>
        public string Name;

        /// <summary>
        /// Type of the parameter.
        /// </summary>
        public System.Data.DbType Type;

        /// <summary>
        /// Value of the parameter.
        /// </summary>
        public string Value;

        public CommandParameter(string Name, System.Data.DbType Type, string Value)
        {
            this.Name = Name;
            this.Type = Type;
            this.Value = Value;
        }

        public static void SetCommandTimeout(System.Data.SqlClient.SqlCommand mySqlCommand)
        {
            int timeout;

            if ((timeout = CommandTimeout) >= 0)
                mySqlCommand.CommandTimeout = timeout;
        }

        public static void SetCommandTimeout(System.Data.Common.DbCommand dbCommand)
        {
            int timeout;

            if ((timeout = CommandTimeout) >= 0)
                dbCommand.CommandTimeout = timeout;
        }
    }

}
