namespace ERPCore.Dtos.Common;

/// <summary>
/// List envelope matching docs/11-BACKEND-PHASE1.md §1.4:
/// <c>{ "items": [...], "pagination": { page, pageSize, totalItems, totalPages } }</c>.
/// </summary>
public sealed record PagedResponse<T>(IReadOnlyList<T> Items, PaginationDto Pagination)
{
    public static PagedResponse<T> Create(IReadOnlyList<T> items, int page, int pageSize, int totalItems)
    {
        var totalPages = pageSize <= 0 ? 0 : (int)Math.Ceiling(totalItems / (double)pageSize);
        return new PagedResponse<T>(items, new PaginationDto(page, pageSize, totalItems, totalPages));
    }
}

/// <summary>Pagination metadata block (docs/11 §1.4).</summary>
public sealed record PaginationDto(int Page, int PageSize, int TotalItems, int TotalPages);
