import { PaginationMeta, PaginationResponse } from '../ok-response.interface';

export function createPaginationMeta(
  start: number,
  limit: number,
  dataCount: number,
  total: number,
): PaginationMeta {
  return {
    currentPage: start,
    itemCount: dataCount,
    itemsPerPage: limit,
    totalItems: +total,
    totalPages: Math.ceil(+total / limit),
  };
}

export function createPaginationResponse<T>(
  response: PaginationResponse<T>,
  start: number,
  limit: number,
) {
  const { data, total } = response;
  const meta = createPaginationMeta(start, limit, data.length, total);
  return {
    data,
    meta,
  };
}
