# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTBadRequest(RESTResponse):
#     status = 400
#     detail = "Bad request"
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTInternalServerError(RESTResponse):
#     status = 500
#     detail = (
#         "The server encountered an unexpected condition that prevented it "
#         "from fulfilling the request"
#     )
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTSuccess(RESTResponse):
#     status = 200


import logging
from il2fb.ds.airbridge.api.http.responses.rest import RESTBadRequest
from il2fb.ds.airbridge.api.http.responses.rest import RESTInternalServerError
from il2fb.ds.airbridge.api.http.responses.rest import RESTSuccess
async def get_health(request):
    pretty = 'pretty' in request.query
    payload = {'status': 'alive'}

    return RESTSuccess(payload=payload, pretty=pretty)


async def get_server_info(request):
    pretty = 'pretty' in request.query
    timeout = request.query.get('timeout')

    try:
        if timeout is not None:
            timeout = float(timeout)
    except Exception:
        LOG.exception("HTTP failed to get server info: incorrect input data")
        return RESTBadRequest(
            detail="incorrect input data",
            pretty=pretty,
        )

    try:
        result = await request.app['console_client'].get_server_info(timeout)
    except Exception:
        LOG.exception("HTTP failed to get server info")
        return RESTInternalServerError(
            detail="failed to get server info",
            pretty=pretty,
        )
    else:

# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTBadRequest(RESTResponse):
#     status = 400
#     detail = "Bad request"
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTInternalServerError(RESTResponse):
#     status = 500
#     detail = (
#         "The server encountered an unexpected condition that prevented it "
#         "from fulfilling the request"
#     )
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTSuccess(RESTResponse):
#     status = 200


# Path: il2fb/ds/airbridge/api/http/views/misc.py
import logging
from il2fb.ds.airbridge.api.http.responses.rest import RESTBadRequest
from il2fb.ds.airbridge.api.http.responses.rest import RESTInternalServerError
from il2fb.ds.airbridge.api.http.responses.rest import RESTSuccess

async def get_health(request):
    pretty = 'pretty' in request.query
    payload = {'status': 'alive'}

    return RESTSuccess(payload=payload, pretty=pretty)


async def get_server_info(request):
    pretty = 'pretty' in request.query
    timeout = request.query.get('timeout')

    try:
        if timeout is not None:
            timeout = float(timeout)
    except Exception:
        LOG.exception("HTTP failed to get server info: incorrect input data")
        return RESTBadRequest(
            detail="incorrect input data",
            pretty=pretty,
        )

    try:
        result = await request.app['console_client'].get_server_info(timeout)
    except Exception:
        LOG.exception("HTTP failed to get server info")
        return RESTInternalServerError(
            detail="failed to get server info",
            pretty=pretty,
        )
    else:

        return RESTSuccess(payload=result, pretty=pretty)