using System;
using InABox.Core;

namespace InABox.DynamicGrid
{
    internal class AuditGrid : DynamicDataGrid<AuditTrail>
    {
        public AuditGrid(Guid entityid)
        {
            EntityID = entityid;
        }

        protected override void DoReconfigure(FluentList<DynamicGridOption> options)
        {
            base.DoReconfigure(options);
            options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.EditRows, DynamicGridOption.SelectColumns);
        }

        public Guid EntityID { get; set; }

        protected override void Reload(Filters<AuditTrail> criteria, Columns<AuditTrail> columns, ref SortOrder<AuditTrail>? sort,
            Action<CoreTable?, Exception?> action)
        {
            criteria.Add(new Filter<AuditTrail>(x => x.EntityID).IsEqualTo(EntityID));
            sort = new SortOrder<AuditTrail>(x => x.Timestamp, SortDirection.Descending);
            base.Reload(criteria, columns, ref sort, action);
        }
    }
}