'use server';
import { NextResponse } from 'next/server';
import { GraphQLClient, gql } from 'graphql-request';

const endpoint = "http://localhost:3001/graphql";

export async function GET(request: Request) {

    const searchParams = new URL(request.url).searchParams;
    const uuid = searchParams.get('uuid');
    if (!uuid) { return NextResponse.json({ error: 'UUID not found in search params' }, { status: 400 }) }
    try {
        const client = new GraphQLClient(endpoint);
        const query = gql`mutation DeleteBuildArea($uuid: String!) { deleteBuildArea(uuid: $uuid) }`;
        const variables = { uuid: uuid };
        const data = await client.request(query, variables);
        return NextResponse.json({ data: data.deleteBuildArea, status: 200 });
    } catch (err: any) {
        console.error(err);
        return NextResponse.json({ error: err.message }, { status: 500 });
    }

}
