# Path: craft_ai/errors.py
# class CraftAiCredentialsError(CraftAiError):
#     """A credentials error occured."""
# 
# class CraftAiBadRequestError(CraftAiError):
#     """An unvalid request was send to craft ai's API."""
# 
# class CraftAiNotFoundError(CraftAiError):
#     """A Not Found Error (404) occured on craft ai's side."""
# 
# class CraftAiUnknownError(CraftAiError):
#     """An unknown error occured in the craft ai client."""
# 
# class CraftAiInternalError(CraftAiError):
#     """An Internal Server Error (500) ocurred on craft ai's side."""


import websockets
import asyncio
import json
from .errors import (
    CraftAiCredentialsError,
    CraftAiBadRequestError,
    CraftAiNotFoundError,
    CraftAiUnknownError,
    CraftAiInternalError,
)


def get_error_from_websocket_status(status_code, message):
    """Give the error corresponding to the status code for websocket.

    :param int status_code: status code of the response to
    a request.
    :param str message: error message given by the response.

    :return: error corresponding to the status code.
    :rtype: Error.
    """

    if status_code == 1007:
        err = CraftAiBadRequestError(message)
    elif status_code == 1003:
        err = CraftAiNotFoundError(message)
    elif status_code == 1002:
        err = CraftAiInternalError(message)
    else:
        err = CraftAiUnknownError(message)
    return err


def initialize_websocket(url, headers):
    web_socket_event_loop = asyncio.get_event_loop()
    try:
        [protocol, uri] = url.split("://")
    except ValueError:

# Path: craft_ai/errors.py
# class CraftAiCredentialsError(CraftAiError):
#     """A credentials error occured."""
# 
# class CraftAiBadRequestError(CraftAiError):
#     """An unvalid request was send to craft ai's API."""
# 
# class CraftAiNotFoundError(CraftAiError):
#     """A Not Found Error (404) occured on craft ai's side."""
# 
# class CraftAiUnknownError(CraftAiError):
#     """An unknown error occured in the craft ai client."""
# 
# class CraftAiInternalError(CraftAiError):
#     """An Internal Server Error (500) ocurred on craft ai's side."""


# Path: craft_ai/websocket_client.py
import websockets
import asyncio
import json
from .errors import (
    CraftAiCredentialsError,
    CraftAiBadRequestError,
    CraftAiNotFoundError,
    CraftAiUnknownError,
    CraftAiInternalError,
)



def get_error_from_websocket_status(status_code, message):
    """Give the error corresponding to the status code for websocket.

    :param int status_code: status code of the response to
    a request.
    :param str message: error message given by the response.

    :return: error corresponding to the status code.
    :rtype: Error.
    """

    if status_code == 1007:
        err = CraftAiBadRequestError(message)
    elif status_code == 1003:
        err = CraftAiNotFoundError(message)
    elif status_code == 1002:
        err = CraftAiInternalError(message)
    else:
        err = CraftAiUnknownError(message)
    return err


def initialize_websocket(url, headers):
    web_socket_event_loop = asyncio.get_event_loop()
    try:
        [protocol, uri] = url.split("://")
    except ValueError:

        raise CraftAiBadRequestError("Invalid url provided")