namespace ERPCore.Common.Models;

/// <summary>Pagination envelope metadata returned alongside a page of items.</summary>
public sealed record PaginationMeta(int Page, int PageSize, int TotalCount)
{
    public int TotalPages => PageSize <= 0 ? 0 : (int)Math.Ceiling(TotalCount / (double)PageSize);
    public bool HasPrevious => Page > 1;
    public bool HasNext => Page < TotalPages;
}

/// <summary>A single page of <typeparamref name="T"/> plus its pagination metadata.</summary>
public sealed class PagedResult<T>
{
    public IReadOnlyList<T> Items { get; init; } = Array.Empty<T>();
    public PaginationMeta Meta { get; init; } = new(1, 0, 0);

    public PagedResult() { }

    public PagedResult(IReadOnlyList<T> items, int page, int pageSize, int totalCount)
    {
        Items = items;
        Meta = new PaginationMeta(page, pageSize, totalCount);
    }
}
