#!/bin/bash

# Domain and txt record value for validation
DOMAIN="_acme-challenge.$CERTBOT_DOMAIN"
TXT_RECORD="$CERTBOT_VALIDATION"

# Get the DNS record id
RECORD_ID=$(curl -X GET "https://api.vercel.com/v2/domains/{{ certbot_vercel_team_id }}/records" \
             -H "Authorization: Bearer {{ certbot_vercel_token }}" \
             -H "Content-Type: application/json" | jq -r ".records[] | select(.name == \"$DOMAIN\" and .value == \"$TXT_RECORD\") | .id")

# Delete the DNS record using Vercel API
curl -X DELETE "https://api.vercel.com/v2/domains/{{ certbot_vercel_team_id }}/records/$RECORD_ID" \
     -H "Authorization: Bearer {{ certbot_vercel_token }}"
