<?php
if (!defined('ABSPATH'))
    exit;

class Dori_Chatbot_Standard_API_Client
{
    public static function activate_trial($user_id, $plan_type = 'free', $token = '')
    {
        $url = Dori_Chatbot_API_Constants::get_server_base_url() . '/billing/active-trial';
        $body = array(
            'user_id'   => $user_id,
            'plan_type' => $plan_type,
        );

        $headers = array('Content-Type' => 'application/json');
        if (!empty($token)) {
            $headers['Authorization'] = 'Bearer ' . $token;
        }

        $response = Dori_Chatbot_API_Client::call_api_post_fast(
            $url,
            $body,
            $headers,
            Dori_Chatbot_API_Client::get_timeout_long()
        );

        return Dori_Chatbot_API_Client::handle_api_response($response, 'StandardAPI: Activate Trial failed');
    }

    public static function get_woocommerce_integration_id($user_id)
    {
        $url = Dori_Chatbot_API_Constants::get_server_base_url() . "/woocommerce/integration-id/{$user_id}";

        $response = Dori_Chatbot_API_Client::call_api_get_fast(
            $url,
            array(),
            Dori_Chatbot_API_Client::get_timeout_long()
        );

        return Dori_Chatbot_API_Client::handle_api_response($response, 'StandardAPI: Fetch Integration ID failed');
    }

    public static function get_aggregate_statistics($user_id)
    {
        $url = Dori_Chatbot_API_Constants::get_server_base_url() . "/aggregate-stat/{$user_id}";

        $response = Dori_Chatbot_API_Client::call_api_get_fast(
            $url,
            array(),
            Dori_Chatbot_API_Client::get_timeout_long()
        );

        return Dori_Chatbot_API_Client::handle_api_response($response, 'StandardAPI: Fetch Aggregate Statistics failed');
    }
}
