import requests
from logging_config import get_logger

logger = get_logger(__name__)

class FetchQueueClient:

    def __init__(self, config):
        self.url = config.FETCH_QUEUE_URL

    def fetch(self, payload):
        logger.info("API request payload: %s", payload)

        try:
            response = requests.post(
                self.url,
                json=payload,
                verify=False,
                timeout=20
            )

            logger.info("API status: %s", response.status_code)

            if not response.ok:
                logger.error("API error response: %s", response.text)

            response.raise_for_status()

            result = response.json()

            logger.debug("API full response: %s", result)

            return result

        except Exception:
            logger.exception("API call failed")
            raise
