#nullable enable
using System;
using System.Collections.Generic;
namespace Schaad.Accounting.Datasets.Analytics
{
public enum AnalyticsPeriod
{
Month,
Quarter,
Year
}
public enum AnalyticsLevel
{
All,
SubClass,
Account,
Text
}
///
/// A position in the drill-down: all expenses → subclass → account → booking-text group.
/// Deeper nodes carry their parents (an account node also has its subclass).
///
public record AnalyticsNode(int? SubClass = null, int? Account = null, string? Text = null)
{
public static readonly AnalyticsNode All = new();
public AnalyticsLevel Level =>
Text != null ? AnalyticsLevel.Text
: Account != null ? AnalyticsLevel.Account
: SubClass != null ? AnalyticsLevel.SubClass
: AnalyticsLevel.All;
}
public record AnalyticsQuery(int FromYear, int ToYear, AnalyticsPeriod Period, AnalyticsNode Node);
public record AnalyticsBreadcrumb(AnalyticsNode Node, string Name);
///
/// One child of the queried node, with its value per period (aligned with
/// ).
///
public record AnalyticsCategory(
AnalyticsNode Node,
string Name,
IReadOnlyList Values,
decimal Total,
decimal Share,
bool CanDrillDown);
///
/// The last year of the range against the year before, over the same months
/// (January to ), so an unfinished year compares fairly.
///
public record YearComparison(int Year, int Months, decimal Current, decimal Previous)
{
public decimal? ChangePercent => Previous == 0 ? null : (Current - Previous) / Math.Abs(Previous) * 100;
}
///
/// Monthly values of the queried node in one year (index 0 = January). Months after the last
/// month with data are null.
///
public record YearProfile(int Year, IReadOnlyList Months, decimal Total);
///
/// A category's value in one year. For the running year only the months with data count, and
/// the change compares the same months of the previous year.
///
public record YearCell(int Year, decimal Value, decimal? ChangePercent);
///
/// One row of the category × year table, in the same order as .
///
public record CategoryYears(AnalyticsNode Node, string Name, bool CanDrillDown, IReadOnlyList Cells, decimal Total);
///
/// A treemap tile: a child of the queried node and, one level deeper, one of its children.
/// is null when the child has no deeper level (booking-text groups).
/// Only positive amounts are included; an area can't show a refund.
///
public record CompositionItem(AnalyticsNode Parent, string ParentName, AnalyticsNode? Child, string? ChildName, decimal Value);
public record AnalyticsResult(
IReadOnlyList Breadcrumb,
IReadOnlyList Periods,
IReadOnlyList Categories,
decimal Total,
int Months,
decimal AveragePerMonth,
YearComparison? Comparison,
IReadOnlyList YearProfiles,
IReadOnlyList CategoryYears,
IReadOnlyList Composition);
}