'use server'

export interface IAlbumData {
    userId: number,
    id: number,
    title: string
}

export default async function createAlbum(data: IAlbumData) {
    try {
        const response = await fetch('https://jsonplaceholder.typicode.com/albums', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(data)
        });

        if (!response.ok)
            throw new Error(`Response status: ${response.status}`);

        return response.json()
    } 
    catch (error) {
        throw new Error(error.message);
    }
}
