<?php
/**
 * Load the Form Notifications.
 *
 * @package miniorange-sms-order-notification-otp-verification/notifications/formsmsnotification
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
if ( ! defined( 'FMSN_DIR' ) ) {
	define( 'FMSN_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'FMSN_URL' ) ) {
	define( 'FMSN_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'FMSN_VERSION' ) ) {
	define( 'FMSN_VERSION', '1.0.0' );
}

/*
|------------------------------------------------------------------------------------------------------
| SOME COMMON FUNCTIONS USED ALL OVER THE Notification
|------------------------------------------------------------------------------------------------------
*/


/**
 * This function is used to handle the notifications get option call. A separate function has been created so that
 * we can manage getting of database values all from one place. Any changes need to be made can be made here
 * rather than having to make changes in all of the add-on files.
 *
 * Calls the mains plugins get_mowc_option function.
 *
 * @param string      $option_string - option name.
 * @param string|null $prefix - prefix of option name.
 * @return mixed
 */
function mowc_get_fmsn_option( $option_string, $prefix = null ) {
	if ( ! is_string( $option_string ) || empty( $option_string ) ) {
		return '';
	}
	$option_string = sanitize_key( $option_string );
	$prefix        = ( null === $prefix ? 'mo_form_sms_' : ( is_string( $prefix ) ? sanitize_key( $prefix ) : '' ) );
	return mowc_get_mowc_option( $prefix . $option_string, '' );
}

/**
 * This function is used to handle the notifications update option call. A separate function has been created so that
 * we can manage getting of database values all from one place. Any changes need to be made can be made here
 * rather than having to make changes in all of the add-on files.
 *
 * Calls the mains plugins update_mowc_option function.
 *
 * @param string      $option_name - option name.
 * @param mixed       $value - value of option name.
 * @param string|null $prefix - prefix before option name.
 * @return bool
 */
function mowc_update_fmsn_option( $option_name, $value, $prefix = null ) {
	if ( ! is_string( $option_name ) || empty( $option_name ) ) {
		return false;
	}
	$option_name = sanitize_key( $option_name );
	$prefix      = ( null === $prefix ? 'mo_form_sms_' : ( is_string( $prefix ) ? sanitize_key( $prefix ) : '' ) );
	return mowc_update_mowc_option( $prefix . $option_name, $value, '' );
}
