using System.Windows;
using InABox.Core;
using Syncfusion.Data;
using Syncfusion.UI.Xaml.Grid;
using Syncfusion.UI.Xaml.Grid.Cells;
using Syncfusion.UI.Xaml.TreeGrid;

namespace InABox.DynamicGrid;

public class DynamicGridIntegerColumn<TEntity> : DynamicGridNumericColumn<TEntity, IntegerEditor, GridNumericColumn, TreeGridNumericColumn> where TEntity : BaseObject
{
    protected override void Configure(GridNumericColumn column, IntegerEditor editor)
    {
        column.NumberGroupSeparator = "";
        column.NumberDecimalDigits = 0;
    }
    protected override void Configure(TreeGridNumericColumn column, IntegerEditor editor)
    {
        column.NumberGroupSeparator = "";
        column.NumberDecimalDigits = 0;
    }
    
    public override GridSummaryColumn? Summary()
    {
        if (Definition == null || Definition.Editor.Summary == Core.Summary.None)
            return null;
        
        var format = Definition.Editor.Summary == Core.Summary.Count
            ? "N0"
            : $"N{Editor!.Digits}";
                            
        var summary = new GridSummaryColumn
        {
            Name = MappingName,
            Format = "{" + (Definition.Editor.Summary == Core.Summary.Sum ? "Sum" : "Count") + ":" + format + "}",
            MappingName = MappingName,
            SummaryType = Definition.Editor.Summary == Core.Summary.Sum
                ? SummaryType.Int32Aggregate 
                : SummaryType.CountAggregate,
            CustomAggregate = new DynamicGridIntegerAggregate()
        };
        
        return summary;
    }

    public DynamicGridIntegerColumn(DynamicGridColumn definition) : base(definition)
    {
    }
}