/**
 * Auto-generated by ${VOCAB.factory}
 * HumanGate Dynamic API Routes
 */

import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/db';
import { VOCAB } from '@/lib/white-label/constants';

export const dynamic = 'force-dynamic';

interface RouteContext {
  params: Promise<{ id: string }>;
}


// GET - Get a single HumanGate by ID
export async function GET(
  request: NextRequest,
  context: RouteContext
) {
  try {
    const { id } = await context.params;

    const humanGate = await prisma.humanGate.findUnique({
      where: { id },
    });

    if (!humanGate) {
      return NextResponse.json(
        { error: 'HumanGate not found' },
        { status: 404 }
      );
    }

    return NextResponse.json(humanGate);
  } catch (error) {
    console.error('Error fetching HumanGate:', error);
    return NextResponse.json(
      { error: 'Failed to fetch HumanGate' },
      { status: 500 }
    );
  }
}


// PUT - Update a HumanGate
export async function PUT(
  request: NextRequest,
  context: RouteContext
) {
  try {
    const { id } = await context.params;
    const body = await request.json();

    // Remove fields that shouldn't be updated
    delete body.id;
    delete body.createdAt;
    delete body.updatedAt;

    const humanGate = await prisma.humanGate.update({
      where: { id },
      data: body,
    });

    return NextResponse.json(humanGate);
  } catch (error) {
    console.error('Error updating HumanGate:', error);
    return NextResponse.json(
      { error: 'Failed to update HumanGate' },
      { status: 500 }
    );
  }
}


// DELETE - Delete a HumanGate
export async function DELETE(
  request: NextRequest,
  context: RouteContext
) {
  try {
    const { id } = await context.params;

    await prisma.humanGate.delete({
      where: { id },
    });

    return NextResponse.json({ success: true });
  } catch (error) {
    console.error('Error deleting HumanGate:', error);
    return NextResponse.json(
      { error: 'Failed to delete HumanGate' },
      { status: 500 }
    );
  }
}
