import type { APIRoute } from 'astro';
import { storage } from '../../lib/storage';

export const prerender = false;

export const GET: APIRoute = async () => {
    try {
        const types = await storage.getAllTypes();

        return new Response(JSON.stringify(types), {
            status: 200,
            headers: {
                'Content-Type': 'application/json',
            },
        });
    } catch (error) {
        console.error('Error in GET /api/types:', error);
        return new Response(JSON.stringify({ error: 'Failed to read word types' }), {
            status: 500,
            headers: {
                'Content-Type': 'application/json',
            },
        });
    }
};
