from typing import Tuple
import requests


def get_bullbear(ticker: str) -> Tuple[int, int, int, int]:
    """Gets bullbear sentiment for ticker [Source: stocktwits]

    Parameters
    ----------
    ticker : str
        Ticker to look at

    Returns
    -------
    int
        Watchlist count
    int
        Number of cases found for ticker
    int
        Number of bullish statements
    int
        Number of bearish statements
    """
    result = requests.get(
        f"https://api.stocktwits.com/api/2/streams/symbol/{ticker}.json"
    )
    if result.status_code == 200:
        result_json = result.json()
        watchlist_count = result_json["symbol"]["watchlist_count"]
        n_cases = 0
        n_bull = 0
        n_bear = 0
        for message in result_json["messages"]:
            if message["entities"]["sentiment"]:
                n_cases += 1
                n_bull += message["entities"]["sentiment"]["basic"] == "Bullish"
                n_bear += message["entities"]["sentiment"]["basic"] == "Bearish"

        return watchlist_count, n_cases, n_bull, n_bear
    return 0, 0, 0, 0