"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateRepositoryInterface = generateRepositoryInterface;
const generator_1 = require("@postxl/generator");
function generateRepositoryInterface(context) {
    const imports = generator_1.ImportGenerator.from(context.repositories.interface.location);
    imports.addType(context.types.dto.create);
    imports.addType(context.types.dto.update);
    imports.addType(context.types.dto.upsert);
    imports.addType(context.actions.execution.interface);
    return /* ts */ `
${imports.generate()}

export interface AsyncInit {
  init(ignoreError?: boolean): Promise<void>
}

export interface ${context.repositories.interface.name}<
  T extends { id: ID } & { createdAt?: any; updatedAt?: any },
  ID extends number | string | boolean
> extends AsyncInit {
  /**
   * Get a single item by its id.
   */
  get(id: ID | null): Promise<T | null>

  /**
   * Get all items.
   */
  getAll(): Promise<Map<ID, T>>

  /**
   * Get all items as an array.
   */
  getAllAsArray(): Promise<T[]>

  filter(filter: {predicate: (item: T) => boolean, prisma: any}): Promise<T[]>
  findFirst(filter: {predicate: (item: T) => boolean, prisma: any}): Promise<T | null>

  count(): Promise<number>

  create?({ item, execution }: { item: CreateDto<T, ID>; execution: IActionExecution }): Promise<T>
  createMany?({ items, execution }: { items: CreateDto<T, ID>[]; execution: IActionExecution }): Promise<T[]>

  update?({ item, execution }: { item: UpdateDto<T, ID>; execution: IActionExecution }): Promise<T>
  updateMany?({ items, execution }: { items: UpdateDto<T, ID>[]; execution: IActionExecution }): Promise<T[]>

  upsert?({ item, execution }: { item: UpsertDto<T, ID>; execution: IActionExecution }): Promise<T>
  upsertMany?({ items, execution }: { items: UpsertDto<T, ID>[]; execution: IActionExecution }): Promise<T[]>

  delete?({ id, execution }: { id: ID; execution: IActionExecution }): Promise<ID>
  deleteMany?({ ids, execution }: { ids: ID[]; execution: IActionExecution }): Promise<ID[]>
}`;
}
//# sourceMappingURL=repository-interface.generator.js.map