import re


def correct_namespace(name, api_name, env_name) -> bool:
    """
    Checks that a name of a thing we want to create in Apigee matches our namespacing conventions.

    e.g. for api_name="canary-api" and env_name="internal-dev"
    |--------------------------------------------------------------+--------|
    | name                                                         | result |
    |--------------------------------------------------------------+--------|
    | "canary-api-internal-dev"                                    | True   |
    | "canary-api-extra-thing-internal-dev"                        | True   |
    | "canary-apiinternal-dev"                                     | False  |
    | "canary-api-internal-dev-application-restricted"             | True   |
    | "canary-api-extra-thing-internal-dev-application-restricted" | True   |
    |--------------------------------------------------------------+--------|

    :param name: Name of thing in Apigee.
    :param api_name: The meta.api.name item from your manifest
    :param env_name: The environment name (e.g. 'internal-dev', 'int', or 'prod')
    """
    regex = f"^{api_name}(-[a-z]+)*-{env_name}(-[a-z]+)*$"
    return bool(re.match(regex, name))