using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using AyaNova.Biz;
namespace AyaNova.PickList
{
    internal class UserPickList : AyaPickList
    {
        public UserPickList()
        {

            DefaultListObjectType = AyaType.User;
            SQLFrom = "from auser";
            AllowedRoles = BizRoles.GetRoleSet(DefaultListObjectType).Select;
            dynamic dTemplate = new JArray();

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

            cm = new JObject();
            cm.fld = "useremployeenumber";
            dTemplate.Add(cm);

            cm = new JObject();
            cm.fld = "usertags";
            dTemplate.Add(cm);

            base.DefaultTemplate = dTemplate.ToString(Newtonsoft.Json.Formatting.None);

            //NOTE: Due to the join, all the sql id and name fields that can conflict with the joined table need to be specified completely
            ColumnDefinitions = new List<AyaPickListFieldDefinition>();
            ColumnDefinitions.Add(new AyaPickListFieldDefinition
            {
                TKey = "Active",
                FieldKey = "useractive",
                ColumnDataType = UiFieldDataType.Bool,
                SqlValueColumnName = "auser.active",
                IsActiveColumn = true
            });
            ColumnDefinitions.Add(new AyaPickListFieldDefinition
            {
                TKey = "Name",
                FieldKey = "username",
                ColumnDataType = UiFieldDataType.Text,
                SqlIdColumnName = "auser.id",
                SqlValueColumnName = "auser.name",
                IsRowId = true
            });
            ColumnDefinitions.Add(new AyaPickListFieldDefinition
            {
                TKey = "UserEmployeeNumber",
                FieldKey = "useremployeenumber",
                ColumnDataType = UiFieldDataType.Text,
                SqlValueColumnName = "auser.employeenumber"
            });

            ColumnDefinitions.Add(new AyaPickListFieldDefinition
            {
                TKey = "Tags",
                FieldKey = "usertags",
                ColumnDataType = UiFieldDataType.Tags,
                SqlValueColumnName = "auser.tags"
            });
        }
    }//eoc
}//eons