import requests

from common.global_logger import logger
import aiohttp


async def send_request_async(push_url, data):
    try:
        async with aiohttp.ClientSession() as session:
            logger.info(f"Push to {push_url}, data = {data}")
            async with session.post(push_url, json=data) as response:
                response_text = await response.text()
                logger.info(f"Response: {response.status}, {response_text}")
    except aiohttp.ClientError as e:
        logger.error(f"Failed to push data: {e}")


def send_request(push_url, data):
    try:
        logger.info(f"Push to {push_url}, data = {data}")
        response = requests.post(push_url, json=data)
        logger.info(f"Response: {response.status_code}, {response.text}")
    except requests.RequestException as e:
        logger.error(f"Failed to push data: {e}")


def get_request(url, headers=None):
    try:
        response = requests.get(url, headers=headers)
        return response.json()
    except requests.RequestException as e:
        logger.error(f"Failed to get data: {e}")
