<?php
/**
 * HappyFenceNG Total Enterprise Security Plugin
 * HAPPYWPRESS is a RazorVue Trademark.
 *
 * @package     HappyFenceNG
 * @developer   Simonluca Scillitani
 * @copyright   2025 RazorVue di Scillitani Simonluca
 * @link        https://razorvue.it
 * @author      RazorVue di Scillitani Simonluca
 * @brand       HappyWPress
 * @uri         https://happywpress.com
 * @set all
 */

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

/**PHPCS -> code compliance: we put useful comments where needed.. */
abstract class HappyFenceNGAProps extends HappyFenceNGSystem {
	/**PHPCS -> code compliance: we put useful comments where needed..
	 *
	 * @var string $store_class .
	 */
	protected string $store_class = HappyFenceNGCStore::class;

	/**PHPCS -> code compliance: we put useful comments where needed.. */
	//phpcs:ignore
	abstract protected function _do();

	/**PHPCS -> code compliance: we put useful comments where needed..
	 *
	 * @param string $property ... it's a property name.
	 * @param string $value .. it's the value of course.
	 */
	public function __set( $property, $value ) {
		try {
			if ( HappyFenceNGPROC::equals( $property, null ) || HappyFenceNGPROC::equals( $property, HappyFenceNGPlaceholder::NOT_INITIALIZED ) ) {
				self::raiseException( 'SET PROPERTY WITH NULL OR INVALID NAME' );

			} elseif (
				( HappyFenceNGPROC::not_equals( $value, HappyFenceNGPlaceholder::IGNORE ) ) &&
				( HappyFenceNGPROC::not_equals( $value, HappyFenceNGPlaceholder::NOT_INITIALIZED ) )
					) {

						$this->store_class::set( static::class, $property, $value );
			}
		} catch ( \Throwable $e ) {
			self::raiseException( 'FATAL::set->' . $e->getMessage() );
		}
	}

	/**PHPCS -> code compliance: we put useful comments where needed..
	 *
	 * @param string $property ... guess what it is.
	 */
	public function __get( $property ) {
		try {
				return $this->store_class::get( static::class, $property, HappyFenceNGPlaceholder::NOT_INITIALIZED );
		} catch ( \Throwable $e ) {
			self::raiseException( 'FATAL::get->' . $e->getMessage() );
			return HappyFenceNGPlaceholder::EMPTY_STRING;
		}
	}

	/**PHPCS -> code compliance: we put useful comments where needed..
	 *
	 * @param string $prop ..it's a property name.
	 * @param string $adefault ... oh really?.
	 */
	protected function jz( string $prop, $adefault ): void {

		if ( HappyFenceNGPROC::not_equals( $adefault, null ) ) {
			try {
				$tmp_v = $this->__get( $prop );
				if ( ( HappyFenceNGPROC::equals( $tmp_v, null ) ) || ( HappyFenceNGPROC::equals( $tmp_v, HappyFenceNGPlaceholder::NOT_INITIALIZED ) ) ) {

					$this->__set( $prop, $adefault );
				}
			} catch ( \Throwable $e ) {
				self::raiseException( 'FATAL::JZ->' . $e->getMessage() );
			}
		} else {
			self::raiseException( 'FATAL::JZ->NULL VALUE?!??!' );
		}
	}

	/**PHPCS -> code compliance: we put useful comments where needed..
	 *
	 * @param string $property ... again is a property.
	 */
	public function __unset( $property ): void {
		try {
			if ( HappyFenceNGPROC::not_equals( $this->__get( $property ), null ) ) {
				$this->__set( $property, HappyFenceNGPlaceholder::NOT_INITIALIZED );
			}
		} catch ( \Throwable $e ) {
			self::raiseException( 'FATAL::UNSET->' . $e->getMessage() );
		}
	}

	/**PHPCS -> code compliance: we put useful comments where needed..
	 *
	 * @param string $property ... again is a property.
	 */
	public function __isset( $property ): bool {
		try {
			switch ( $this->__get( $property ) ) {
				case HappyFenceNGPlaceholder::NOT_INITIALIZED:
				case HappyFenceNGPlaceholder::IGNORE:
				case HappyFenceNGPlaceholder::INVALID:
				case HappyFenceNGPlaceholder::NO_RESULT:
				case null:
					return false;
				default:
					return true;
			}
		} catch ( \Throwable $e ) {
			self::raiseException( 'FATAL::ISSET->' . $e->getMessage() );
			return false;
		}
	}
}
