'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');
    const buildID = searchParams.get('buildID');
    console.dir({ uuid, buildID }, { depth: null });
    if (!uuid) { return NextResponse.json({ error: 'UUID not found in search params' }, { status: 400 }) }
    try {
        const client = new GraphQLClient(endpoint);
        const query = gql`mutation DeleteCompany($buildID: String!, $uuid: String!) { deleteCompany(buildID: $buildID, uuid: $uuid) }`;
        const data = await client.request(query, { buildID, uuid });
        return NextResponse.json({ data: data.deleteUserType, status: 200 });
    } catch (err: any) {
        console.error(err);
        return NextResponse.json({ error: err.message }, { status: 500 });
    }

}
