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

class Dori_Chatbot_Mori_Style_Client
{
    public static function register($email, $password, $phone_number, $website_url, $platform_selection, $how_find_us)
    {
        $url = Dori_Chatbot_API_Constants::get_mori_style_base_url() . '/api/wordpress/register';

        $body = array(
            'email' => $email,
            'password' => $password,
            'phoneNumber' => $phone_number,
            'websiteUrl' => $website_url,
            'platformSelection' => $platform_selection,
            'howFindUs' => $how_find_us,
        );

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

        return Dori_Chatbot_API_Client::handle_api_response($response, 'MoriStyle: Registration failed');
    }

    public static function resend_sms($user_id)
    {
        $url = Dori_Chatbot_API_Constants::get_mori_style_base_url() . '/api/wordpress/resend-sms';

        $body = array(
            'userId' => $user_id,
        );

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

        return Dori_Chatbot_API_Client::handle_api_response($response, 'MoriStyle: Resend SMS failed');
    }

    public static function verify_sms($user_id, $code)
    {
        $url = Dori_Chatbot_API_Constants::get_mori_style_base_url() . '/api/wordpress/verify-sms';

        $body = array(
            'userId' => $user_id,
            'code' => $code,
        );

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

        return Dori_Chatbot_API_Client::handle_api_response($response, 'MoriStyle: Verify SMS failed');
    }

    public static function extract_status($user_id, $save_empty_bot)
    {
        $url = Dori_Chatbot_API_Constants::get_mori_style_base_url() . '/api/wordpress/extract-status';

        $body = array(
            'userId' => $user_id,
            'saveEmptyBot' => $save_empty_bot,
        );

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

        return Dori_Chatbot_API_Client::handle_api_response($response, 'MoriStyle: Extract Status failed');
    }

    public static function activate_trial($user_id)
    {
        $url = Dori_Chatbot_API_Constants::get_mori_style_base_url() . '/api/wordpress/activate-trial';

        $body = array(
            'userId' => $user_id,
        );

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

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

    public static function get_integration_id($user_id)
    {
        $url = Dori_Chatbot_API_Constants::get_mori_style_base_url() . "/api/wordpress/get-integration-id?userId={$user_id}";

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

        return Dori_Chatbot_API_Client::handle_api_response($response, 'MoriStyle: Get Integration ID failed');
    }
}
