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

class Dori_Chatbot_WooCommerce_Integration
{
    public static function init()
    {
        Dori_Chatbot_WooCommerce_API_Keys::init();
        Dori_Chatbot_WooCommerce_Session::init();
        Dori_Chatbot_WooCommerce_Order_Tracker::init();
        Dori_Chatbot_WooCommerce_Cart_Tracker::init();
    }

    public static function is_store_fully_connected()
    {
        $credentials = Dori_Chatbot_Cache_Manager::get_api_credentials();
        $client_id = $credentials['client_id'];
        $client_secret = $credentials['client_secret'];
        $sharing_id = Dori_Chatbot_Cache_Manager::get_sharing_id();

        if (empty($client_id)) {
            return false;
        }

        if (empty($client_secret)) {
            return false;
        }

        if (empty($sharing_id)) {
            return false;
        }

        if (is_admin()) {
            $consumer_key = get_option('dori-chatbot-wc-consumer-key');
            $consumer_secret = get_option('dori-chatbot-wc-consumer-secret');
            $wc_keys_valid = !empty($consumer_key) && !empty($consumer_secret);
        } else {
            $wc_keys_valid = Dori_Chatbot_WooCommerce_API_Keys::get_and_test_keys();
        }

        if ($wc_keys_valid === false) {
            return false;
        }

        return true;
    }

    public static function verify_store_connection_fresh($skip_api_test = true)
    {
        $client_id = get_option('dori-chatbot-client-id', '');
        $client_secret = get_option('dori-chatbot-client-secret', '');
        $sharing_id = get_option('dori-chatbot-sharing-id', '');

        if (empty($client_id)) {
            return false;
        }

        if (empty($client_secret)) {
            return false;
        }

        if (empty($sharing_id)) {
            return false;
        }

        $wc_keys_valid = Dori_Chatbot_WooCommerce_API_Keys::get_and_test_keys(true, $skip_api_test);

        if ($wc_keys_valid === false) {
            return false;
        }

        return true;
    }
}
