using System.Collections.Generic;
using Sockeye.Biz;
namespace Sockeye.DataList
{
    internal class AttachmentDataList : DataListProcessingBase
    {
        public AttachmentDataList(long translationId)
        {
            DefaultListAType = SockType.FileAttachment;
            SQLFrom = "from afileattachment left join auser on (afileattachment.attachedByUserId=auser.id)";
            var RoleSet = BizRoles.GetRoleSet(DefaultListAType);
            AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
            DefaultColumns = new List<string>() { "displayfilename", "object", "size", "username", "notes", "exists" };
            DefaultSortBy = new Dictionary<string, string>() { { "displayfilename", "+" }, { "size", "-" } };


            FieldDefinitions = new List<DataListFieldDefinition>();

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "FileAttachment",
                FieldKey = "displayfilename",
                SockType = (int)SockType.FileAttachment,
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlIdColumnName = "afileattachment.id",
                SqlValueColumnName = "afileattachment.displayfilename",
                IsRowId = true
            });

            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 = "AttachmentExists",
                FieldKey = "exists",
                UiFieldDataType = (int)UiFieldDataType.Bool,
                SqlValueColumnName = "afileattachment.exists"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "Object",
                FieldKey = "object",
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlIdColumnName = "afileattachment.AttachToObjectid",
                SqlValueColumnName = $"AYGETNAME(afileattachment.AttachToObjectid, afileattachment.attachtoatype,{translationId})",
                SqlATypeColumnName = "afileattachment.attachtoatype",
                Translate = true
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "FileSize",
                FieldKey = "size",
                UiFieldDataType = (int)UiFieldDataType.MemorySize,
                SqlValueColumnName = "afileattachment.size"
            });

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


        }


    }//eoc
}//eons