using System.Collections.Generic;
using Sockeye.Models;
using Sockeye.Biz;
namespace Sockeye.DataList
{
    internal class MemoDataList : DataListProcessingBase, IDataListInternalCriteria
    {
        public MemoDataList(long translationId)
        {

            DefaultListAType = SockType.Memo;
            SQLFrom = "from amemo left join auser on (amemo.fromid=auser.id)";
            var RoleSet = BizRoles.GetRoleSet(DefaultListAType);
            AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
            DefaultColumns = new List<string>() { "MemoSubject", "MemoFromID", "MemoSent", "MemoViewed" };
            DefaultSortBy = new Dictionary<string, string>() { { "MemoSent", "-" } };
            FieldDefinitions = new List<DataListFieldDefinition>();

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "MemoSubject",
                FieldKey = "MemoSubject",
                SockType = (int)SockType.Memo,
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlIdColumnName = "amemo.id",
                SqlValueColumnName = "amemo.name",
                IsRowId = true
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "MemoMessage",
                FieldKey = "MemoMessage",
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlValueColumnName = "amemo.notes"
            });

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

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "MemoSent",
                FieldKey = "MemoSent",
                UiFieldDataType = (int)UiFieldDataType.DateTime,
                SqlValueColumnName = "amemo.sent"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "MemoReplied",
                FieldKey = "MemoReplied",
                UiFieldDataType = (int)UiFieldDataType.Bool,
                SqlValueColumnName = "amemo.replied"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "MemoViewed",
                FieldKey = "MemoViewed",
                UiFieldDataType = (int)UiFieldDataType.Bool,
                SqlValueColumnName = "amemo.viewed"
            });


            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "Tags",
                FieldKey = "MemoTags",
                UiFieldDataType = (int)UiFieldDataType.Tags,
                SqlValueColumnName = "amemo.tags"
            });

            //META column 
            FieldDefinitions.Add(new DataListFieldDefinition
            {
                FieldKey = "metamemoto",
                UiFieldDataType = (int)UiFieldDataType.InternalId,
                SqlIdColumnName = "amemo.toid",
                SqlValueColumnName = "amemo.toid",
                IsMeta = true
            });

            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom1", FieldKey = "MemoCustom1", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom2", FieldKey = "MemoCustom2", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom3", FieldKey = "MemoCustom3", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom4", FieldKey = "MemoCustom4", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom5", FieldKey = "MemoCustom5", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom6", FieldKey = "MemoCustom6", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom7", FieldKey = "MemoCustom7", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom8", FieldKey = "MemoCustom8", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom9", FieldKey = "MemoCustom9", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom10", FieldKey = "MemoCustom10", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom11", FieldKey = "MemoCustom11", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom12", FieldKey = "MemoCustom12", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom13", FieldKey = "MemoCustom13", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom14", FieldKey = "MemoCustom14", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom15", FieldKey = "MemoCustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });
            FieldDefinitions.Add(new DataListFieldDefinition { TKey = "MemoCustom16", FieldKey = "MemoCustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amemo.customfields" });

        }

        public List<DataListFilterOption> DataListInternalCriteria(long currentUserId, AuthorizationRoles userRoles, string clientCriteria)
        {
            List<DataListFilterOption> ret = new List<DataListFilterOption>();

            DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metamemoto" };
            FilterOption.Items.Add(new DataListColumnFilter() { value = currentUserId.ToString(), op = DataListFilterComparisonOperator.Equality });

            ret.Add(FilterOption);
            return ret;
        }

    }//eoc
}//eons