export type DjAPIEndpoint =
    | "/rp-articles"
    | "/blog-entries"
;

type BlogEntry = {
    title: string,
    slug: string;
    createdAt: string,
    updatedAt: string,
    tags?: string[],
};

type RPArticle = {
    title: string,
    slug: string;
    titleDe: string,
    titleEn: string,
    author: string,
    tags?: string[],
};

export interface DjAPIResultMap extends Record<DjAPIEndpoint, unknown> {
    "/rp-articles": RPArticle[];
    "/blog-entries": BlogEntry[];
}

export type DjAPIResult = DjAPIResultMap[DjAPIEndpoint];

export default async function getDjAPI<T extends DjAPIEndpoint>(
    hostUrl: string,
    endpoint: T,
): Promise<DjAPIResultMap[typeof endpoint]> {
    return await (await fetch(`${hostUrl}/api${endpoint}`)).json();
}
