import { Presenter } from "@erp/core/api";
import { Criteria } from "@repo/rdx-criteria/server";
import { Collection } from "@repo/rdx-utils";
import { {{pascalCase name}} } from "../../../domain";

export class List{{pascalCase name}}sPresenter extends Presenter {
  private _mapEntity(entity: {{pascalCase name}}) {
    return { id: entity.id.toPrimitive(), name: entity.name };
  }

  toOutput(params: { entities: Collection<{{pascalCase name}}>; criteria: Criteria }): any {
    const { entities, criteria } = params;
    return {
      page: criteria.pageNumber,
      per_page: criteria.pageSize,
      total_pages: Math.ceil(entities.total() / criteria.pageSize),
      total_items: entities.total(),
      items: entities.map((e) => this._mapEntity(e)),
      metadata: { entity: "{{kebabCase name}}s", criteria: criteria.toJSON() }
    };
  }
}
