import requests
import Apikeys
import sys
import pprint

pp = pprint.PrettyPrinter(indent=4)
APIKEY = Apikeys.SUPPLIERPROD
LP_UUID = sys.argv[1]
HEADERS = {
    "accept": "*/*",
    "x-api-key": APIKEY,
    "content-type": "application/json",
}
# Category Advisory Services
# 6afe6b7e-088b-4dfa-9a0f-e8aefcd81cdf

# Sandbox - Ascent LP
# 6ef5c9db-81d7-427c-846b-babb9a9a2ad1

def get_enrollments():
    page = 0
    person_list = []
    while True:
        page += 1
        url = f"https://api2.northpass.com/v2/learning_paths/{LP_UUID}/enrollments?limit=100&page={page}"
        response = requests.get(url, headers=HEADERS)
        data = response.json()
        nextlink = data["links"]

        for items in data["data"]:
            person_uuid = items["attributes"]["person_id"]
            person_list.append(person_uuid)

        if "next" not in nextlink:
            break

    print(person_list)
    print(len(person_list))

    for person in person_list:
        delete_enrollments(person, LP_UUID)

def delete_enrollments(person_uuid, lp_uuid):
    url = f"https://api2.northpass.com/v1/people/{person_uuid}/relationships/learning_paths"
    payload = { "data": [{ "type": "enrolled-courses", "id": lp_uuid  }] }
    delsponse = requests.delete(url, headers=HEADERS, json=payload)
    print(delsponse.status_code)

if __name__ == "__main__":
    get_enrollments()
