using System.Collections.Generic;
using AyaNova.Biz;
namespace AyaNova.DataList
{
    internal class TestWidgetDataList : AyaDataList
    {
        //No JOINS just straight up widgets
        public TestWidgetDataList()
        {
            ListKey = nameof(TestWidgetDataList);
            DefaultListObjectType = AyaType.Widget;
            SQLFrom = "from awidget left outer join auser on (awidget.userid=auser.id)";
            FullListAllowedRoles = BizRoles.GetRoleSet(DefaultListObjectType).ReadFullRecord;
            MiniListAllowedRoles = AuthorizationRoles.All;//anyone (so can select on forms)

            DefaultDataListDisplayTemplate = @"
            {
                ""full"":[""widgetname"",""widgetserial"",""widgetdollaramount"",""widgetroles"",""widgetstartdate"",""widgetactive"",""username""],
                ""mini"":[""widgetname"",""widgetserial""]
            }
            ";

            //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>();
            FieldDefinitions.Add(new AyaDataListFieldDefinition { FieldKey = "df", AyaObjectType = (int)AyaType.Widget, SqlIdColumnName = "awidget.id" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                LtKey = "WidgetName",
                FieldKey = "widgetname",
                AyaObjectType = (int)AyaType.Widget,
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlIdColumnName = "awidget.id",
                SqlValueColumnName = "awidget.name"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                LtKey = "WidgetSerial",
                FieldKey = "widgetserial",
                UiFieldDataType = (int)UiFieldDataType.Integer,
                SqlValueColumnName = "awidget.serial"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                LtKey = "WidgetDollarAmount",
                FieldKey = "widgetdollaramount",
                UiFieldDataType = (int)UiFieldDataType.Currency,
                SqlValueColumnName = "awidget.dollaramount"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                LtKey = "WidgetCount",
                FieldKey = "widgetcount",
                UiFieldDataType = (int)UiFieldDataType.Integer,
                SqlValueColumnName = "awidget.count"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                LtKey = "WidgetRoles",
                FieldKey = "widgetroles",
                UiFieldDataType = (int)UiFieldDataType.Enum,
                EnumType = typeof(AuthorizationRoles).ToString(),
                SqlValueColumnName = "awidget.roles"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                LtKey = "WidgetStartDate",
                FieldKey = "widgetstartdate",
                UiFieldDataType = (int)UiFieldDataType.DateTime,
                SqlValueColumnName = "awidget.startdate"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                LtKey = "WidgetEndDate",
                FieldKey = "widgetenddate",
                UiFieldDataType = (int)UiFieldDataType.DateTime,
                SqlValueColumnName = "awidget.enddate"
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                LtKey = "WidgetNotes",
                FieldKey = "widgetnotes",
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlValueColumnName = "awidget.notes"
            });

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

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