import { Page } from './page';
import { Sort } from './sort';

export class Query {
  fields: string[];
  filter: string[];
  sort: Sort;
  page?: Page;

  constructor(data: Partial<Query>) {
    this.fields = data?.fields ?? [];
    this.filter = data?.filter ?? [];
    this.sort = new Sort(data?.sort ?? {});
    if (data?.page) this.page = new Page(data?.page);
  }

  isValid(): boolean {
    return true;
  }

  toString(): string {
    return [
      this.fields.join(','),
      '',
      this.page?.toString(),
      this.sort.toString(),
    ].join(';');
  }
}
