import requests

class ChatBot:
    def __init__(self):

    def chat(self, message):
        try:
            url = f"https://developer-server-g05b.onrender.com/chat_ai"

            data = {
                "message": message
            }

            res = requests.post(url, json=data, timeout=10)

            if res.status_code == 200:
                return res.json()
            else:
                return {"error": f"Status code: {res.status_code}"}

        except requests.exceptions.ConnectionError as e:
            return {"error": f"Connection Error: {e}"}

        except requests.exceptions.Timeout as e:
            return {"error": f"Timeout Error: {e}"}

        except requests.exceptions.RequestException as e:
            return {"error": f"Request Error: {e}"}

        except Exception as e:
            return {"error": f"Unknown Error: {e}"}