// src/pages/api/auth/status.ts 
import type { APIRoute } from 'astro';
import { withAPIAuth } from '../../../utils/auth.js';
import { apiResponse, handleAPIRequest } from '../../../utils/api.js';

export const prerender = false;

export const GET: APIRoute = async ({ request }) => {
  return await handleAPIRequest(async () => {
    const contributionAuth = await withAPIAuth(request, 'contributions');
    const aiAuth = await withAPIAuth(request, 'ai');
    
    return apiResponse.success({
      authenticated: contributionAuth.authenticated || aiAuth.authenticated,
      contributionAuthRequired: contributionAuth.authRequired,
      aiAuthRequired: aiAuth.authRequired,
      contributionAuthenticated: contributionAuth.authenticated,
      aiAuthenticated: aiAuth.authenticated,
      expires: contributionAuth.session?.exp ? new Date(contributionAuth.session.exp * 1000).toISOString() : null
    });
  }, 'Status check failed');
};