import { Presenter } from "./presenter";

export interface PagingEntity {
  before?: string | null;
  after?: string | null;
}

export interface PaginatedInput<DataInput> {
  data: DataInput;
  paging: PagingEntity;
}

export interface PaginatedOutput<DataOutput> {
  data: DataOutput;
  paging: PagingEntity;
}

// tslint:disable-next-line
export class PageableDataLayoutPresenter<DataInput, DataOutput> implements Presenter<PaginatedInput<DataInput>, PaginatedOutput<DataOutput>> {
  private _outputJSONSchema = { // tslint:disable-line
    type: "object",
    properties: {
      data: this.presenter.outputJSONSchema(),
      paging: {
        type: "object",
        properties: {
          before: {
            type: "string",
            description: "This field is nullable. Value can be null"
          },
          after: {
            type: "string",
            description: "This field is nullable. Value can be null"
          },
        },
      },
    },
  };

  constructor(
    private presenter: Presenter<DataInput, DataOutput>,
  ) {}

  public outputJSONSchema() {
    return this._outputJSONSchema;
  }

  public async present(input: PaginatedInput<DataInput>) {
    const dataOutput = await this.presenter.present(input.data);

    return {
      data: dataOutput,
      paging: input.paging,
    };
  }
}

import { Presenter } from "./presenter";

export interface PagingEntity {
  before?: string;
  after?: string;
}

export interface PaginatedInput<DataInput> {
  data: DataInput;
  paging: PagingEntity;
}

export interface PaginatedOutput<DataOutput> {
  data: DataOutput;
  paging: PagingEntity;
}

// tslint:disable-next-line
export class PageableDataLayoutPresenter<DataInput, DataOutput> implements Presenter<PaginatedInput<DataInput>, PaginatedOutput<DataOutput>> {
  private _outputJSONSchema = { // tslint:disable-line
    type: "object",
    properties: {
      data: this.presenter.outputJSONSchema(),
      paging: {
        type: "object",
        properties: {
          before: {
            type: "string",
          },
          after: {
            type: "string",
          },
        },
      },
    },
  };

  constructor(
    private presenter: Presenter<DataInput, DataOutput>,
  ) {}

  public outputJSONSchema() {
    return this._outputJSONSchema;
  }

  public async present(input: PaginatedInput<DataInput>) {
    const dataOutput = await this.presenter.present(input.data);

    return {
      data: dataOutput,
      paging: input.paging,
    };
  }
}

Revert "Update PagingEntity on PageableDataLayoutPresenter"
Revert "Update PagingEntity on PageableDataLayoutPresenter"

This reverts commit cddc1a357b525cb47253d238ac764e6b092cc578.
