using System.ComponentModel;
namespace Svrnty.Sample.AI.Tools;
///
/// Business tool for querying database and business metrics
///
public class DatabaseQueryTool
{
// Simulated data - replace with actual database queries via CQRS
private static readonly Dictionary MonthlyRevenue = new()
{
["2025-01"] = 50000m,
["2025-02"] = 45000m,
["2025-03"] = 55000m,
["2025-04"] = 62000m,
["2025-05"] = 58000m,
["2025-06"] = 67000m
};
private static readonly List<(string Name, string State, string Tier)> Customers = new()
{
("Acme Corp", "California", "Enterprise"),
("TechStart Inc", "California", "Startup"),
("BigRetail LLC", "Texas", "Enterprise"),
("SmallShop", "New York", "SMB"),
("MegaCorp", "California", "Enterprise")
};
[Description("Get revenue for a specific month in YYYY-MM format")]
public decimal GetMonthlyRevenue(
[Description("Month in YYYY-MM format, e.g., 2025-01")] string month)
{
return MonthlyRevenue.TryGetValue(month, out var revenue) ? revenue : 0m;
}
[Description("Calculate total revenue between two months (inclusive)")]
public decimal GetRevenueRange(
[Description("Start month in YYYY-MM format")] string startMonth,
[Description("End month in YYYY-MM format")] string endMonth)
{
var total = 0m;
foreach (var kvp in MonthlyRevenue)
{
if (string.Compare(kvp.Key, startMonth, StringComparison.Ordinal) >= 0 &&
string.Compare(kvp.Key, endMonth, StringComparison.Ordinal) <= 0)
{
total += kvp.Value;
}
}
return total;
}
[Description("Count customers by state")]
public int CountCustomersByState(
[Description("US state name, e.g., California")] string state)
{
return Customers.Count(c => c.State.Equals(state, StringComparison.OrdinalIgnoreCase));
}
[Description("Count customers by tier (Enterprise, SMB, Startup)")]
public int CountCustomersByTier(
[Description("Customer tier: Enterprise, SMB, or Startup")] string tier)
{
return Customers.Count(c => c.Tier.Equals(tier, StringComparison.OrdinalIgnoreCase));
}
[Description("Get list of customer names by state and tier")]
public string GetCustomers(
[Description("US state name, optional")] string? state = null,
[Description("Customer tier, optional")] string? tier = null)
{
var filtered = Customers.AsEnumerable();
if (!string.IsNullOrWhiteSpace(state))
{
filtered = filtered.Where(c => c.State.Equals(state, StringComparison.OrdinalIgnoreCase));
}
if (!string.IsNullOrWhiteSpace(tier))
{
filtered = filtered.Where(c => c.Tier.Equals(tier, StringComparison.OrdinalIgnoreCase));
}
var names = filtered.Select(c => c.Name).ToList();
return names.Any() ? string.Join(", ", names) : "No customers found";
}
}