import axios from 'axios';

const shop = 'veloxautomotive.myshopify.com';
const accessToken = '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';

const client = axios.create({
    baseURL: `https://${shop}/admin/api/2025-10/graphql.json`,
    headers: {
        'X-Shopify-Access-Token': accessToken,
        'Content-Type': 'application/json',
    },
});

const run = async () => {
    const query = `
      query {
        shop {
          fulfillmentServices {
            id
            serviceName
          }
        }
      }
    `;

    const { data } = await client.post('', { query });
    const services = data.data.shop.fulfillmentServices;

    for (const service of services) {
        if (service.serviceName.includes("Data4Autos")) {
            const mutation = `
              mutation {
                fulfillmentServiceDelete(id: "${service.id}") {
                  deletedId
                  userErrors {
                    field
                    message
                  }
                }
              }
            `;
            const response = await client.post('', { query: mutation });
            const result = response.data.data.fulfillmentServiceDelete;

            if (result.userErrors?.length) {
                console.error(`Error deleting ${service.serviceName}:`, result.userErrors);
            } else {
                console.log(`Deleted: ${service.serviceName}`);
            }
            console.log(`Would delete: ${service.serviceName} with ID: ${service.id}`);
        }


    }
};

run();
