using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using AyaNova.Biz;
namespace AyaNova.DataList
{
    internal class TestWidgetUserEmailDataList : AyaDataList
    {
        /*
            Select awidget.id, awidget.name, auser.name, auser.id, auseroptions.emailaddress
               from awidget
               left outer join auser on (awidget.userid=auser.id)
               left outer join auseroptions on (auser.id=auseroptions.userid)
               order by auseroptions.emailaddress desc
                                   */


        public TestWidgetUserEmailDataList()
        {
            DefaultListObjectType = AyaType.Widget;
            SQLFrom = "from awidget left outer join auser on (awidget.userid=auser.id) left outer join auseroptions on (auser.id=auseroptions.userid)";
            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 = "username";
            dlistView.Add(cm);

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

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

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


            //NOTE: First field after df is used as the title above the narrow grid view so it should be the name of the item to be shown that is most identifiable
            FieldDefinitions = new List<AyaDataListFieldDefinition>();
            //DEPRECATED FieldDefinitions.Add(new AyaDataListFieldDefinition { FieldKey = "df", AyaObjectType = (int)AyaType.Widget, SqlIdColumnName = "awidget.id" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                FieldKey = "widgetname",
                TKey = "WidgetName",
                UiFieldDataType = (int)UiFieldDataType.Text,
                AyaObjectType = (int)AyaType.Widget,
                SqlIdColumnName = "awidget.id",
                SqlValueColumnName = "awidget.name",
                IsRowId = true
            });
            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 = "UserEmailAddress",
                FieldKey = "emailaddress",
                SqlValueColumnName = "auseroptions.emailaddress",
                UiFieldDataType = (int)UiFieldDataType.EmailAddress
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "Active",
                FieldKey = "widgetactive",
                SqlValueColumnName = "awidget.active",
                UiFieldDataType = (int)UiFieldDataType.Bool
            });

        }
    }//eoc
}//eons