using System;
using System.Threading;
using InABox.Core;

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

        protected override void DoReconfigure(DynamicGridOptions options)
        {
            base.DoReconfigure(options);
            options.RecordCount = true;
            options.EditRows = true;
            options.SelectColumns = true;
        }

        public Guid EntityID { get; set; }

        protected override void Reload(
            Filters<AuditTrail> criteria, Columns<AuditTrail> columns, ref SortOrder<AuditTrail>? sort,
            CancellationToken token, 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, token, action);
        }
    }
}