namespace ERPCore.Dtos.Common;

/// <summary>
/// Shared paging/sorting query binding (docs/11-BACKEND-PHASE1.md §1.5). Page size
/// is clamped to <see cref="MaxPageSize"/> to enforce pagination bounds
/// (02-SECURITY B.6). Bind from the query string on list endpoints.
/// </summary>
public class PageQuery
{
    public const int MaxPageSize = 200;
    public const int DefaultPageSize = 20;

    private int _page = 1;
    private int _pageSize = DefaultPageSize;

    /// <summary>1-based page number (default 1).</summary>
    public int Page
    {
        get => _page;
        set => _page = value < 1 ? 1 : value;
    }

    /// <summary>Page size (default 20, clamped to 1..200).</summary>
    public int PageSize
    {
        get => _pageSize;
        set => _pageSize = value < 1 ? DefaultPageSize : Math.Min(value, MaxPageSize);
    }

    /// <summary>Free-text search term (<c>q</c>).</summary>
    public string? Q { get; set; }

    /// <summary>Sort spec, e.g. <c>name</c> or <c>-createdAt</c>.</summary>
    public string? Sort { get; set; }

    public int Skip => (Page - 1) * PageSize;
}
