<?php
/**
 * Exception Class
 *
 * This class extends the standard PHP Exception class to provide
 * custom exception handling with additional miniOrange-specific error codes.
 *
 * @package miniorange-sms-order-notification-otp-verification/helper
 * @since   1.0.0
 */

namespace WCSMSOTP\Helper;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Exception Class
 *
 * This class extends the standard PHP Exception class to provide
 * custom exception handling with additional miniOrange-specific error codes.
 */
if ( ! class_exists( 'MoException' ) ) {
	/**
	 * Exception Class
	 *
	 * This class extends the standard PHP Exception class to provide
	 * custom exception handling with additional miniOrange-specific error codes.
	 */
	class MoException extends \Exception {

		/**
		 * MiniOrange-specific exception code.
		 *
		 * @var string|int
		 */
		private $mo_code;

		/**
		 * Constructor.
		 *
		 * Initializes the exception with a miniOrange-specific code,
		 * message, and standard exception code.
		 *
		 * @param string|int $mo_code  MiniOrange-specific exception code.
		 * @param string     $message  Exception message.
		 * @param int        $code     Standard exception code. Default 0.
		 */
		public function __construct( $mo_code, $message, $code = 0 ) {
			if ( ! is_string( $mo_code ) && ! is_int( $mo_code ) ) {
				$mo_code = '';
			}
			if ( ! is_string( $message ) ) {
				$message = '';
			}
			if ( ! is_int( $code ) ) {
				$code = 0;
			}
			$this->mo_code = $mo_code;
			parent::__construct( $message, $code, null );
		}

		/**
		 * Get miniOrange exception code.
		 *
		 * Retrieves the miniOrange-specific exception code.
		 *
		 * @return string|int The miniOrange exception code.
		 */
		public function getmo_code() {
			return $this->mo_code;
		}
	}
}
