using GraphQL.Types;

namespace Books.Api.GraphQL.Types;

/// <summary>
/// GraphQL type for account balance information within a period.
/// Combines account metadata with aggregated debit/credit totals from the Ledger service.
/// </summary>
public class AccountBalanceType : ObjectGraphType<AccountBalanceDto>
{
    public AccountBalanceType()
    {
        Name = "AccountBalance";
        Description = "Account with balance information for a period";

        Field(x => x.Id, type: typeof(IdGraphType))
            .Description("The account ID");
        Field(x => x.AccountNumber)
            .Description("The account number (e.g., 1000, 56100)");
        Field(x => x.Name)
            .Description("The account name");
        Field(x => x.AccountType)
            .Description("The account type (Asset, Liability, Equity, Revenue, Expense, etc.)");
        Field(x => x.IsActive)
            .Description("Whether the account is active");
        Field(x => x.TotalDebits)
            .Description("Total debit amount for the period");
        Field(x => x.TotalCredits)
            .Description("Total credit amount for the period");
        Field(x => x.NetChange)
            .Description("Net change (debits - credits) for the period");
        Field(x => x.EntryCount)
            .Description("Number of journal entries affecting this account in the period");
    }
}

/// <summary>
/// DTO for account balance data returned by the accountBalances query.
/// </summary>
public class AccountBalanceDto
{
    public string Id { get; set; } = "";
    public string AccountNumber { get; set; } = "";
    public string Name { get; set; } = "";
    public string AccountType { get; set; } = "";
    public bool IsActive { get; set; }
    public decimal TotalDebits { get; set; }
    public decimal TotalCredits { get; set; }
    public decimal NetChange { get; set; }
    public int EntryCount { get; set; }
}
