/**
 * Dynamic llms.txt Route
 *
 * Serves llms.txt only when custom content is set in settings.
 * No content is generated by default.
 * See: https://llmstxt.org/
 */

import { NextResponse } from 'next/server';
import { getSettingByKey } from '@/lib/repositories/settingsRepository';

export async function GET() {
  try {
    const customLlms = await getSettingByKey('llms_txt');

    if (customLlms && typeof customLlms === 'string' && customLlms.trim()) {
      return new NextResponse(customLlms.trim(), {
        headers: {
          'Content-Type': 'text/plain; charset=utf-8',
          'Cache-Control': 'public, max-age=86400, s-maxage=86400',
        },
      });
    }

    return new NextResponse(null, { status: 404 });
  } catch (error) {
    console.error('[llms.txt] Error:', error);
    return new NextResponse(null, { status: 404 });
  }
}
