using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using AyaNova.Biz;
namespace AyaNova.DataList
{
    internal class TestWidgetDataList : AyaDataList
    {
        public TestWidgetDataList()
        {
            DefaultListObjectType = AyaType.Widget;
            SQLFrom = "from awidget left outer join auser on (awidget.userid=auser.id)";
            var RoleSet = BizRoles.GetRoleSet(DefaultListObjectType);
            AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;

            //Default ListView
            dynamic dlistView = new JArray();

            dynamic cm = new JObject();
            cm.fld = "widgetname";
            dlistView.Add(cm);

            cm = new JObject();
            cm.fld = "widgetserial";
            dlistView.Add(cm);

            cm = new JObject();
            cm.fld = "widgetdollaramount";
            dlistView.Add(cm);

            cm = new JObject();
            cm.fld = "widgetusertype";
            dlistView.Add(cm);

            cm = new JObject();
            cm.fld = "widgetstartdate";
            dlistView.Add(cm);

            cm = new JObject();
            cm.fld = "widgetactive";
            dlistView.Add(cm);

            cm = new JObject();
            cm.fld = "username";
            dlistView.Add(cm);

            DefaultListView = dlistView.ToString(Newtonsoft.Json.Formatting.None);



            // DefaultDataListView = @"
            // {
            //     [{key:""COLUMN UNIQUE KEY ID",sort:"-" or "+",filter:{any:true/false,items:[{FILTER OBJECT SEE BELOW}]} }, {key:"second column unique key"},{...etc...}]

            //     ""full"":[""widgetname"",""widgetserial"",""widgetdollaramount"",""widgetusertype"",""widgetstartdate"",""widgetactive"",""username""],

            // }
            // ";

            //NOTE: Due to the join, all the sql id and name fields that can conflict with the joined (in this case User) table need to be specified completely
            FieldDefinitions = new List<AyaDataListFieldDefinition>();
            //DEPRECATED: FieldDefinitions.Add(new AyaDataListFieldDefinition { FieldKey = "df", AyaObjectType = (int)AyaType.Widget, SqlIdColumnName = "awidget.id", IsFilterable = false, IsSortable = false, });

            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "WidgetName",
                FieldKey = "widgetname",
                AyaObjectType = (int)AyaType.Widget,
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlIdColumnName = "awidget.id",
                SqlValueColumnName = "awidget.name",
                IsRowId = true
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "WidgetSerial",
                FieldKey = "widgetserial",
                UiFieldDataType = (int)UiFieldDataType.Integer,
                SqlValueColumnName = "awidget.serial"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "WidgetDollarAmount",
                FieldKey = "widgetdollaramount",
                UiFieldDataType = (int)UiFieldDataType.Currency,
                SqlValueColumnName = "awidget.dollaramount"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "WidgetCount",
                FieldKey = "widgetcount",
                UiFieldDataType = (int)UiFieldDataType.Integer,
                SqlValueColumnName = "awidget.count"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "UserType",
                FieldKey = "widgetusertype",
                UiFieldDataType = (int)UiFieldDataType.Enum,
                EnumType = AyaNova.Util.StringUtil.TrimTypeName(typeof(UserType).ToString()),
                SqlValueColumnName = "awidget.usertype"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "WidgetStartDate",
                FieldKey = "widgetstartdate",
                UiFieldDataType = (int)UiFieldDataType.DateTime,
                SqlValueColumnName = "awidget.startdate"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "WidgetEndDate",
                FieldKey = "widgetenddate",
                UiFieldDataType = (int)UiFieldDataType.DateTime,
                SqlValueColumnName = "awidget.enddate"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "WidgetNotes",
                FieldKey = "widgetnotes",
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlValueColumnName = "awidget.notes"
            });

            //FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "User", FieldKey = "userid", UiFieldDataType = (int)AyaUiFieldDataType.Text, AyaObjectType = (int)AyaType.User });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                FieldKey = "username",
                TKey = "User",
                UiFieldDataType = (int)UiFieldDataType.Text,
                AyaObjectType = (int)AyaType.User,
                SqlIdColumnName = "auser.id",
                SqlValueColumnName = "auser.name"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "Active",
                FieldKey = "widgetactive",
                UiFieldDataType = (int)UiFieldDataType.Bool,
                SqlValueColumnName = "awidget.active"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "Tags",
                FieldKey = "widgettags",
                UiFieldDataType = (int)UiFieldDataType.Tags,
                SqlValueColumnName = "awidget.tags"
            });

            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom1", FieldKey = "widgetcustom1", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom2", FieldKey = "widgetcustom2", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom3", FieldKey = "widgetcustom3", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom4", FieldKey = "widgetcustom4", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom5", FieldKey = "widgetcustom5", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom6", FieldKey = "widgetcustom6", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom7", FieldKey = "widgetcustom7", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom8", FieldKey = "widgetcustom8", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom9", FieldKey = "widgetcustom9", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom10", FieldKey = "widgetcustom10", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom11", FieldKey = "widgetcustom11", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom12", FieldKey = "widgetcustom12", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom13", FieldKey = "widgetcustom13", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom14", FieldKey = "widgetcustom14", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom15", FieldKey = "widgetcustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition { TKey = "WidgetCustom16", FieldKey = "widgetcustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "awidget.customfields" });
        }
    }//eoc
}//eons