using System.Collections.Generic;
using System.Windows.Media;
using InABox.Core;
using Syncfusion.Data;
using Syncfusion.UI.Xaml.Grid;
using Syncfusion.UI.Xaml.TreeGrid;

namespace InABox.DynamicGrid;

public class DynamicGridCurrencyColumn<TEntity> : DynamicGridNumericColumn<TEntity, CurrencyEditor, GridCurrencyColumn, TreeGridCurrencyColumn> where TEntity : BaseObject
{

    protected override void Configure(GridCurrencyColumn column, CurrencyEditor editor)
    {
        column.CurrencyDecimalDigits = GetDigits(editor);
        column.CurrencyGroupSeparator = ",";
        column.CurrencyGroupSizes = new Int32Collection(new[] { 3, 3, 3, 3, 3, 3 });
    }

    protected override void Configure(TreeGridCurrencyColumn column, CurrencyEditor editor)
    {
        column.CurrencyDecimalDigits = GetDigits(editor);
        column.CurrencyGroupSeparator = ",";
        column.CurrencyGroupSizes = new Int32Collection(new[] { 3, 3, 3, 3, 3, 3 });
    }

    public override GridSummaryColumn? Summary()
    {
        if (Definition == null || Definition.Editor.Summary == Core.Summary.None)
            return null;
        
        var format = Definition.Editor.Summary == Core.Summary.Count
            ? "N0"
            : $"C{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.DoubleAggregate
                : SummaryType.CountAggregate,
            CustomAggregate = new DynamicGridDoubleAggregate()
        };
        return summary;
    }

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