namespace adas_core.Domain.Models.Responses;

/// <summary>
/// Represents a generic response wrapper for paginated data, typically used to return a subset of items along with associated pagination metadata.
/// </summary>
/// <typeparam name="T">The type of the items contained in the paginated response.</typeparam>
/// <!-- aidoc:v1 sig=3c8b06d -->
public class PaginationResponse<T>
{
    /// <summary>
    /// Initializes a new instance of <see cref="PaginationResponse{T}"/> with the supplied page items and pagination metadata, deriving the total page count from <paramref name="totalRecords"/> and <paramref name="pageSize"/>.
    /// </summary>
    /// <param name="data">The <see cref="List{T}"/> of items included in the current page.</param>
    /// <param name="pageNumber">The number of the current page.</param>
    /// <param name="pageSize">The maximum number of items per page.</param>
    /// <param name="totalRecords">The total number of records available across all pages.</param>
    /// <!-- aidoc:v1 sig=bbc53e5 body=c9e44a7 -->
    public PaginationResponse(List<T> data, int pageNumber, int pageSize, long totalRecords)
    {
        PageNumber = pageNumber;
        PageSize = pageSize;
        Data = data;
        TotalRecords = totalRecords;
        var totalPages = TotalRecords / (double)PageSize;
        var roundedTotalPages = Convert.ToInt64(Math.Ceiling(totalPages));
        TotalPages = roundedTotalPages;
    }

    public int PageNumber { get; set; }
    public int PageSize { get; set; }

    public long TotalPages { get; set; }
    public long TotalRecords { get; set; }
    public List<T> Data { get; set; }
}