namespace OpenNest.Data;
///
/// One bounded page request for browsing drawing sets (GET /api/sets/query).
/// The server filters and pages in SQL; the client and server share these bounds.
///
public sealed class DrawingSetQuery
{
public const int DefaultLimit = 100;
public const int MaxLimit = 500;
public const int MaxSearchLength = 200;
///
/// Case-insensitive (ASCII) substring of name, customer or notes. Blank means no filter.
///
public string Search { get; init; } = "";
/// Exact customer, compared by . Blank means any.
public string Customer { get; init; } = "";
public bool IncludeArchived { get; init; }
/// Column to order by; ties are broken by id in the same direction.
public DrawingSetSortField Sort { get; init; } = DrawingSetSortField.SavedAt;
/// Largest/newest/Z first when true (the default, newest saved first).
public bool Descending { get; init; } = true;
public int Offset { get; init; }
public int Limit { get; init; } = DefaultLimit;
/// The search text as matched: trimmed, never null.
public string NormalizedSearch => (Search ?? "").Trim();
/// The first violated bound, or null when the query may be sent.
public string? GetValidationError()
{
if (!Enum.IsDefined(Sort))
return "sort must be a supported column.";
if (Offset < 0)
return "offset must be zero or greater.";
if (Limit < 1 || Limit > MaxLimit)
return $"limit must be between 1 and {MaxLimit}.";
return DrawingLibraryRules.TextError("search", NormalizedSearch, MaxSearchLength)
?? DrawingLibraryRules.TextError("customer", Customer ?? "", DrawingLibraryRules.MaxTextLength);
}
}