import type { APIRoute, GetStaticPaths } from 'astro'

import database from '@/data/domande-esami.yaml'

export const getStaticPaths = (() => {
    return Object.keys(database.names).map(course => ({
        params: { course },
    }))
}) satisfies GetStaticPaths

export const GET: APIRoute = ({ params: { course } }) => {
    return new Response(
        JSON.stringify({
            groups: [],
            names: Object.fromEntries(Object.entries(database.names).filter(([key]) => key === course)),
            questions: database.questions.filter(question => question.course === course),
        }),
        {
            headers: {
                'content-type': 'application/json',
            },
        },
    )
}
