using System.Collections.Generic;
using Sockeye.Biz;
using Sockeye.Models;

namespace Sockeye.DataList
{
    internal class CustomerNoteDataList : DataListProcessingBase, IDataListInternalCriteria
    {
        public CustomerNoteDataList(long translationId)
        {
            DefaultListAType = SockType.CustomerNote;
            SQLFrom = "from acustomernote left join auser on (acustomernote.userid=auser.id)";
            var RoleSet = BizRoles.GetRoleSet(DefaultListAType);
            AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
            DefaultColumns = new List<string>() { "notedate", "notes", "username" };
            DefaultSortBy = new Dictionary<string, string>() { { "notedate", "-" } };

            FieldDefinitions = new List<DataListFieldDefinition>();

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


            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "CustomerNoteNotes",
                FieldKey = "notes",
                SockType = (int)SockType.CustomerNote,
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlIdColumnName = "acustomernote.id",
                SqlValueColumnName = "acustomernote.notes",
                IsRowId = true
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "CustomerNoteNoteDate",
                FieldKey = "notedate",
                UiFieldDataType = (int)UiFieldDataType.DateTime,
                SqlValueColumnName = "acustomernote.notedate"
            });

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

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


        public List<DataListFilterOption> DataListInternalCriteria(long currentUserId, AuthorizationRoles userRoles, string clientCriteria)
        {
            List<DataListFilterOption> ret = new List<DataListFilterOption>();
            //ClientCriteria MUST be CustomerId
            if (string.IsNullOrWhiteSpace(clientCriteria))
                throw new System.ArgumentNullException("CustomerNoteDataList - ClientCriteria is empty, should be Customer ID");

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

            ret.Add(FilterOption);
            return ret;
        }


    }//eoc
}//eons