// film.service.ts

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

@Injectable({
  providedIn: 'root'
})
export class FilmService {
  private Film = Parse.Object.extend('Film');

 constructor() {}

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

 async searchFilm(queryParams: any):Promise<Parse.Object[]>{
  const query = new Parse.Query(this.Film);
  if (queryParams.name) {
    query.contains('name', queryParams.name);
  }
  return await query.find();
 }
 
  // async getFilms(): Promise<any[]> {
  //   const Film = Parse.Object.extend('Film');
  //   const query = new Parse.Query(Film);
  //   return await query.find();
  // }

  // async getSortedFilmsByRating(): Promise<any[]> {
  //   const Film = Parse.Object.extend('Film');
  //   const query = new Parse.Query(Film);
  //   query.descending('rating');
  //   return await query.find();
  // }

}