# Path: ceagle/api/client.py
# CONF = config.CONF
# FAKE_CLIENT_MAP = {
#     "security": security.Client,
# }
# class UnknownService(Exception):
# class Client(base.Client):
#     def get(self, uri="/", **kwargs):
# def get_client(service_name):
# 
# Path: ceagle/api_fake_data/fake_regions.py
# REGIONS_NUM = 4
# def regions(detailed=False):
# def get_regions(detailed):


import flask
from oss_lib import config
from ceagle.api import client
from ceagle.api_fake_data import fake_regions
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.



CONF = config.CONF

bp = flask.Blueprint("regions", __name__)


@bp.route("", defaults={"detailed": False})
@bp.route("/detailed", defaults={"detailed": True})
@fake_regions.get_regions
def get_regions(detailed):
    regions = {}

    for service_name in CONF["services"].keys():
        if service_name == "infra":
            continue   # TODO(boris-42): This should not be checked here.
        service_client = client.get_client(service_name)

        resp, code = service_client.get("/api/v1/regions")
        if code != 200:
            # FIXME ADD LOGS HERE
            continue
        for r in resp:
            regions.setdefault(r, {"services": []})
            regions[r]["services"].append(service_name)


# Path: ceagle/api/client.py
# CONF = config.CONF
# FAKE_CLIENT_MAP = {
#     "security": security.Client,
# }
# class UnknownService(Exception):
# class Client(base.Client):
#     def get(self, uri="/", **kwargs):
# def get_client(service_name):
# 
# Path: ceagle/api_fake_data/fake_regions.py
# REGIONS_NUM = 4
# def regions(detailed=False):
# def get_regions(detailed):


# Path: ceagle/api/v1/regions.py
import flask
from oss_lib import config
from ceagle.api import client
from ceagle.api_fake_data import fake_regions

#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.



CONF = config.CONF

bp = flask.Blueprint("regions", __name__)


@bp.route("", defaults={"detailed": False})
@bp.route("/detailed", defaults={"detailed": True})
@fake_regions.get_regions
def get_regions(detailed):
    regions = {}

    for service_name in CONF["services"].keys():
        if service_name == "infra":
            continue   # TODO(boris-42): This should not be checked here.
        service_client = client.get_client(service_name)

        resp, code = service_client.get("/api/v1/regions")
        if code != 200:
            # FIXME ADD LOGS HERE
            continue
        for r in resp:
            regions.setdefault(r, {"services": []})
            regions[r]["services"].append(service_name)


    if not detailed: