<?php

defined('ABSPATH') || exit;

class BundlePress_Remote_API
{
    private static $base_url = 'https://dominopress.com/api/woocommerce/events';

    public static function post($endpoint, $body = [])
    {
        $response = wp_remote_post(self::$base_url . $endpoint, [
            'body' => json_encode($body),
            'headers' => [
                'Content-Type' => 'application/json',
            ],
            'timeout' => 30,
        ]);

        if (is_wp_error($response)) {
            return $response;
        }

        return json_decode(wp_remote_retrieve_body($response), true);
    }

    public static function get($endpoint, $args = [])
    {
        $url = add_query_arg($args, self::$base_url . $endpoint);
        $response = wp_remote_get($url, [
            'timeout' => 30,
        ]);

        if (is_wp_error($response)) {
            return $response;
        }

        return json_decode(wp_remote_retrieve_body($response), true);
    }
}
