using System.Collections.Generic;
using Sockeye.Biz;
namespace Sockeye.DataList
{
    internal class EventDataList : DataListProcessingBase
    {
        public EventDataList(long translationId)
        {
            //NOTE: used this type because it's full BizFull and read only Bizrestricted only which is appropriate and there is no event type
            DefaultListAType = SockType.Global;
            SQLFrom = "from aevent left join auser on (aevent.userid=auser.id)";
            var RoleSet = BizRoles.GetRoleSet(DefaultListAType);
            AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
            DefaultColumns = new List<string>() { "eventcreated", "event", "object", "SockType", "username", "textra" };
            DefaultSortBy = new Dictionary<string, string>() { { "eventcreated", "-" } };
           

            FieldDefinitions = new List<DataListFieldDefinition>();

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "EventCreated",
                FieldKey = "eventcreated",
                UiFieldDataType = (int)UiFieldDataType.DateTime,
                SqlValueColumnName = "aevent.created"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "Event",
                FieldKey = "event",
                UiFieldDataType = (int)UiFieldDataType.Enum,
                EnumType = Sockeye.Util.StringUtil.TrimTypeName(typeof(SockEvent).ToString()),
                SqlValueColumnName = "aevent.sockevent"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "SockType",
                FieldKey = "SockType",
                UiFieldDataType = (int)UiFieldDataType.Enum,
                EnumType = Sockeye.Util.StringUtil.TrimTypeName(typeof(SockType).ToString()),
                SqlValueColumnName = "aevent.socktype"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "Object",
                FieldKey = "object",
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlIdColumnName = "aevent.sockid",
                SqlValueColumnName = $"AYGETNAME(aevent.sockid, aevent.socktype,{translationId})",
                SqlATypeColumnName = "aevent.socktype"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                FieldKey = "username",
                TKey = "User",
                UiFieldDataType = (int)UiFieldDataType.Text,
                SockType = (int)SockType.User,
                SqlIdColumnName = "auser.id",
                SqlValueColumnName = "auser.name"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "EventTextra",
                FieldKey = "textra",
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlValueColumnName = "aevent.textra"
            });
        }
    }//eoc
}//eons