using System.Collections.Generic;
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()
        {
            ListKey = nameof(TestWidgetUserEmailDataList);
            SQLFrom = "from awidget left outer join auser on (awidget.userid=auser.id) left outer join auseroptions on (auser.id=auseroptions.userid)";
            FullListAllowedRoles = BizRoles.GetRoleSet(DefaultListObjectType).ReadFullRecord;
            MiniListAllowedRoles = AuthorizationRoles.AllExceptCustomers;//anyone but clients who shouldn't see users email addresses (so can select on forms)
            DefaultListObjectType = AyaType.Widget;
            DefaultDataListDisplayTemplate = @"
            {
                ""full"":[""widgetname"",""username"",""emailaddress"",""widgetactive""],
                ""mini"":[""widgetname"",""username"",""emailaddress""]
            }
            ";

            FieldDefinitions = new List<AyaDataListFieldDefinition>();
            FieldDefinitions.Add(new AyaDataListFieldDefinition { FieldKey = "df", AyaObjectType = (int)AyaType.Widget, SqlIdColumnName = "awidget.id" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                FieldKey = "widgetname",
                LtKey = "WidgetName",
                UiFieldDataType = (int)UiFieldDataType.Text,
                AyaObjectType = (int)AyaType.Widget,
                SqlIdColumnName = "awidget.id",
                SqlValueColumnName = "awidget.name"
            });
            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 = "UserEmailAddress",
                FieldKey = "emailaddress",
                SqlValueColumnName = "auseroptions.emailaddress",
                UiFieldDataType = (int)UiFieldDataType.EmailAddress
            });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                LtKey = "Active",
                FieldKey = "widgetactive",
                SqlValueColumnName = "awidget.active",
                UiFieldDataType = (int)UiFieldDataType.Bool
            });

        }
    }//eoc
}//eons