import{createCursor as l}from"../../providers/database/pagination/utils/create-cursor.js";import{transformToCamelCase as g}from"../../providers/database/pagination/utils/transform-to-camel-case.js";import{DEFAULT_LIMIT as f}from"../../providers/database/pagination/limit.js";function h(e){return!!(e.after||e.before)}function P(e,r,i){const n=h(r),t=r.limit??f;if(n){if(r.before)return!0;if(r.after)return e.length===t}return i!==void 0&&r.skip!==void 0?r.skip+t<i:i!==void 0?t<i:e.length===t}function b(e){return!!(e.after||e.before||e.skip!==void 0&&e.skip>0)}function k({data:e,params:r,totalCount:i,nameTransformationsFromDatabase:n={},hasMore:t}){if(!e.length)return{object:"list",items:[],page:{total:0,limit:r.limit??f,hasNextPage:!1,hasPrevPage:!1,startCursor:null,endCursor:null}};const o=r.sort?.[0],s=n[o?.field]||g(o?.field||"id"),u=t??P(e,r,i),c=b(r);return{object:"list",items:e,page:{total:i??0,limit:r.limit??f,hasNextPage:u,hasPrevPage:c,startCursor:l(e[0],s),endCursor:l(e[e.length-1],s)}}}export{k as prepareListResponse};
