namespace FinancialApi.Domain.Entities; public enum AccountType { Liability, Debit, Credit, Revenue } public record Account(int Id, decimal Balance, AccountType Type) { public Account ApplyPosting(decimal amount, EntryType entryType) { if (amount <= 0) { throw new ArgumentException("Amount must be positive."); } var newBalance = entryType == EntryType.Credit ? Balance + amount : Balance - amount; ; if (newBalance < 0 && Type is AccountType.Liability or AccountType.Debit or AccountType.Revenue) { throw new InsufficientFundsException("Insufficient funds."); } return this with { Balance = newBalance }; } } public class InsufficientFundsException(string insufficientFunds) : Exception(insufficientFunds);