// src/app/api/secondary-options/[id]/confirm-delete/route.ts
import { NextRequest, NextResponse } from 'next/server';

export async function DELETE(
  request: NextRequest,
  { params }:  { params: Promise<{ id: string }> }
) {
  const { id } = await params;

  try {
    const deleteResponse = await fetch(
      `${process.env.BACKEND_URL}/api/v1/secondary-options/${id}`,
      {
        method: 'DELETE',
        headers: {
          'Content-Type': 'application/json',
        },
      }
    );

    if (!deleteResponse.ok) {
      const errorData = await deleteResponse.json();
      return NextResponse.json(
        { status: 'error', message: errorData.message || `Error deleting secondary option` },
        { status: deleteResponse.status }
      );
    }

    return NextResponse.json(
      { status: 'success', message: 'Secondary option and all its relationships deleted successfully' },
      { status: 200 }
    );
  } catch (error) {
    console.error(`Error in DELETE /api/v1/secondary-options/${id}/confirm-delete:`, error);
    return NextResponse.json(
      { status: 'error', message: 'Internal server error' },
      { status: 500 }
    );
  }
}
