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

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[]>('playlists');

}

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

}

export async function getSongs() {
    
    return await axios.get<ISong[]>('http://localhost:3000/songs');

}

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

}

export async function getGenres() {
    
    return await axios.get<IGenre[]>('http://localhost:3000/genres');

}

export async function getAds() {
    
    return await axios.get<IAdvertisement[]>('http://localhost:3000/ads');

}