<?php

if (! defined('ABSPATH')) exit;

function docuchat_plugin_activate()
{
    echo wp_json_encode(docuchat_process_activate());
    wp_die();
}


function docuchat_process_activate()
{
    try {
        if (
            isset($_POST["status"]) && !empty($_POST["status"]) &&
            isset($_POST["nonce"]) && !empty($_POST["nonce"])  &&
            wp_verify_nonce( wp_unslash($_POST["nonce"]), 'activate' )
        ) {

            $getOptions = unserialize(get_option(DOCUCHAT_ACTIVATION_SERIALIZACION));

            $getOptions[1] = false;
            $getOptions[2] = "active";

            update_option(DOCUCHAT_ACTIVATION_SERIALIZACION, serialize($getOptions));

            return array("status" => 200, "message" => "plugin activated successfully");
        } else {
            return array("status" => 400, "message" => "plugin activation failed");
        }
    } catch (\Throwable $th) {
        return array("status" => 400, "message" => "Error registering data: " . $th->getMessage());
    }
}
