<?php

function docuchat_plugin_deletePartialLocalData() { 
   echo wp_json_encode(docuchat_renove_partial_data());   
   wp_die();  
}

function docuchat_renove_partial_data() { 
    try {
        if ( isset($_POST["nonce"]) && !empty($_POST["nonce"]) &&
         wp_verify_nonce( wp_unslash( $_POST["nonce"]) , 'partialDelete' )
        ) {
            $array_of_local_options = array('docuchat_activation_serializacion', 'docuchat_token', 'docuchat_email_registred');
            foreach ($array_of_local_options as $local_option) {
                if( $local_option != DOCUCHAT_ACTIVATION_SERIALIZACION) {
                    delete_option($local_option);
                }
                if( $local_option == DOCUCHAT_ACTIVATION_SERIALIZACION ) { 
                    update_option( DOCUCHAT_ACTIVATION_SERIALIZACION, serialize(['active', false, false, false ]) );   
                }
            }

            return array("status" => 200, "message" => "Partial data removed successfully");
        
        } else {
            return array("status" => 400, "message" => "Partial data removal failed" );
        }

     } catch (\Throwable $th) {
        return array("status" => 400, "message" => "Error registering data: " . $th->getMessage());
    }        
     
}