import axios from "axios";
import { IAdvertisement, IGenre, IPlaylist, ISong } from "../models/IModels";

const localhost = process.env.REACT_APP_DATABASE;

export function getPlaylistsByGenre(genre: string, playlists: IPlaylist[]) {
    return playlists.filter((playlist: IPlaylist) => playlist.genres.includes(genre));
    
}

export async function getPlaylists() {
    
    return await axios.get<IPlaylist[]>(`${localhost}playlists`);

}
export async function getPlaylist(id: string) {
    
    return await axios.get<IPlaylist[]>(`${localhost}playlists/` + id);

}

export async function getSongs() {
    
    return await axios.get<ISong[]>(`${localhost}songs`);

}

export async function getSong(id: string) {
    
    return await axios.get<IPlaylist[]>(`${localhost}songs/` + id);

}

export async function getGenres() {
    
    return await axios.get<IGenre[]>(`${localhost}genres`);

}

export async function getAds() {
    
    return await axios.get<IAdvertisement[]>(`${localhost}advertisements`);

}