import requests
from warnings import warn


def _get_stages(base_url, app_id) -> list[int]:
    """
    get all stages id. if a stage is not completed, it is skipped
    """
    resp = requests.get(f"{base_url}/api/v1/applications/{app_id}/stages")

    if resp.status_code != 200:
        raise RuntimeError(
            f"get request not ok - status code: {resp.status_code} - {base_url}/api/v1/applications/{app_id}/stages"
        )

    js = resp.json()

    #for i in range(len(js)):
    #    print("==============")
    #    print(js[i])
    #    print("==============")

    stage_ids = []
    for i in range(len(js)):
        record = js[i]
        status = record["status"]
        stageid = record['stageId']
        if status != "COMPLETE":
            warn(f"skipped stage {stageid} with status {status}")
            continue
        else:
            stage_ids.append(stageid)

    #print(stage_ids)
    return stage_ids