/**
 * Tesa Fashion Photos API
 * GET /api/tesa/photos - Fetch Tesa's fashion photos
 */

import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/db';

export const dynamic = 'force-dynamic';

export async function GET(request: NextRequest) {
  try {
    const searchParams = request.nextUrl.searchParams;
    const limit = parseInt(searchParams.get('limit') || '10');
    const offset = parseInt(searchParams.get('offset') || '0');
    
    const photos = await prisma.tesFashion.findMany({
      where: { isPrivate: false },
      orderBy: { date: 'desc' },
      take: Math.min(limit, 50), // Cap at 50
      skip: offset,
    });
    
    const total = await prisma.tesFashion.count({
      where: { isPrivate: false }
    });

    return NextResponse.json({
      photos,
      pagination: {
        total,
        limit,
        offset,
        hasMore: offset + photos.length < total
      }
    });
  } catch (error) {
    console.error('Failed to fetch Tesa photos:', error);
    return NextResponse.json(
      { error: 'Failed to fetch photos' },
      { status: 500 }
    );
  }
}
