import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, throwError, BehaviorSubject } from 'rxjs';
import { catchError, retry, map, tap } from 'rxjs/operators';
import { User } from '../interfaces/user';
import { Discoteca } from '../discoteca';
import { UserLogin } from '../interfaces/user-login';
import { DiscotecaI } from '../interfaces/discoteca-i';
import { Eventoi } from '../interfaces/eventoi';


@Injectable({
  providedIn: 'root'
})
export class ApiService {

  baseUrl = "http://localhost:3307/api/consultas";

  constructor(private http: HttpClient) {

   }


  validateUser(user: UserLogin): Observable<User>{

    return this.http.post<User>(this.baseUrl+"/users", user)
      
  }

  getUserDiscoteca(discotecaId: number): Observable<DiscotecaI>{

    return this.http.post<DiscotecaI>(this.baseUrl+"/discoteca", { "id": discotecaId});

  }

  postEvento(eventoInterface: Eventoi): Observable<Eventoi>{

    return this.http.post<Eventoi>(this.baseUrl+"/evento", eventoInterface);
    
  }

  getEventos(): Observable<Eventoi[]>{

    return this.http.get<Eventoi[]>(this.baseUrl+"/evento");
  }

  getEventosDiscoteca(discotecaID: number): Observable<Eventoi[]>{

      return this.http.post<Eventoi[]>(this.baseUrl+"/eventosDiscoteca", {"id": discotecaID});


  }




}
