package configloader

import (
    "errors"
    "strconv"
)

// Validates an institution ID.
// A valid institution ID returns a HTTP 200 response code when queried
// <instance_url> + "/institution/" + institution_id.
// Returns either the entered instance URL or an error.
func ValidateInstitutionId(institutionId int, instanceUrl string) (int, error) {

    if institutionId < 1 {
        return 0, errors.New("Institution ID cannot be negative")
    }

    statusCode, err := HttpGetStatusCode(instanceUrl + "/institution/" + strconv.Itoa(institutionId))
	if err != nil {
		return 0, err
	}

	if statusCode != 200 {
        return 0, errors.New("The institution page does not respond with HTTP 200, the institution does not seem to exist")
	}

    return institutionId, nil

}
