using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using AyaNova.Biz;
namespace AyaNova.DataList
{
    internal class ReportDataList : AyaDataList
    {

        public ReportDataList()
        {
            DefaultListObjectType = AyaType.Report;
            SQLFrom = "from aReport";
            var RoleSet = BizRoles.GetRoleSet(DefaultListObjectType);
            AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;

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

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

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



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

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



            //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>();
            //DPRECATED FieldDefinitions.Add(new AyaDataListFieldDefinition { FieldKey = "df", AyaObjectType = (int)AyaType.User, SqlIdColumnName = "auser.id" });
            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "Report",
                FieldKey = "name",
                AyaObjectType = (int)AyaType.Report,
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlIdColumnName = "aReport.id",
                SqlValueColumnName = "aReport.name",
                IsRowId = true
            });


            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "AyaType",
                FieldKey = "objecttype",
                UiFieldDataType = (int)UiFieldDataType.Enum,
                EnumType = AyaNova.Util.StringUtil.TrimTypeName(typeof(AyaType).ToString()),
                SqlValueColumnName = "areport.ObjectType"
            });


            FieldDefinitions.Add(new AyaDataListFieldDefinition
            {
                TKey = "Active",
                FieldKey = "active",
                UiFieldDataType = (int)UiFieldDataType.Bool,
                SqlValueColumnName = "aReport.active"
            });



        }
    }//eoc
}//eons