using System.Collections.Generic;
using Sockeye.Biz;
namespace Sockeye.DataList
{
    internal class NotificationDeliveryLogDataList : DataListProcessingBase
    {
        public NotificationDeliveryLogDataList(long translationId)
        {
            DefaultListAType = SockType.OpsNotificationSettings;
            SQLFrom = @"from anotifydeliverylog
                        left join anotifysubscription on anotifysubscription.id = anotifydeliverylog.notifysubscriptionid
                        left join auser on anotifysubscription.userid=auser.id";
            var RoleSet = BizRoles.GetRoleSet(DefaultListAType);
            AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
            DefaultColumns = new List<string>() { "Processed", "NotifyEventType", "SockType", "User", "Failed", "Errors" };
            DefaultSortBy = new Dictionary<string, string>() { { "Processed", "-" } };
            FieldDefinitions = new List<DataListFieldDefinition>();

            // FieldDefinitions.Add(new DataListFieldDefinition
            // {
            //     TKey = "NotifySubscription",
            //     FieldKey = "NotifySubscription",
            //     SockType = (int)SockType.NotifySubscription,
            //     UiFieldDataType = (int)UiFieldDataType.Text,
            //     SqlIdColumnName = "anotifysubscription.id",
            //     SqlValueColumnName = "anotifysubscription.id",
            //     IsRowId = false
            // });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "Processed",
                FieldKey = "Processed",
                UiFieldDataType = (int)UiFieldDataType.DateTime,
                SqlValueColumnName = "anotifydeliverylog.processed"
            });

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

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

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "Failed",
                FieldKey = "Failed",
                UiFieldDataType = (int)UiFieldDataType.Bool,
                SqlValueColumnName = "anotifydeliverylog.fail"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "Errors",
                FieldKey = "Errors",
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlValueColumnName = "anotifydeliverylog.error"
            });

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

        }
    }//eoc
}//eons