import { Injectable } from '@angular/core';
import Parse from 'parse';

@Injectable({
  providedIn: 'root'
})
export class PetService {
  private Pet = Parse.Object.extend('Pet');
  constructor() {
 
  }

  async getPets(queryParams: any): Promise<Parse.Object[]> {
    const query = new Parse.Query(this.Pet);
    if (queryParams.name) {
      query.contains('name', queryParams.name);
    }
    if (queryParams.type) {
      query.equalTo('type', queryParams.type);
    }
    if (queryParams.sortByPrice) {
      query.ascending('price');
    } else {
      query.descending('price');
    }
    return await query.find();
  }
}