<?php
/**
 *
 * Main model
 *
 * @package halloween-panda
 * @subpackage _models
 * @since Halloween Panda 1.0.0
 */

namespace PixHalloweenPanda\Models;

defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

/**
 * Class Halloween Panda Model Main
 *
 * @category Model
 * @package  halloween-panda
 * @author  IV | PIXOLETTE
 * @license  http://www.pixollete.com
 * @link     http://www.pixollete.com
 */
class Main {

	/**
	 * The option_name of plugin data options
	 *
	 * @access public
	 * @var string
	 */
	public $plugin_options = 'pix_hp_options';

	/**
	 * Will store in an array all plugin options
	 *
	 * @access public
	 * @var array
	 */
	public $options_data = array();

	/**
	 * The class constructor. Init plugin options data;
	 *
	 * @access public
	 * @var function
	 */
	function __construct() {

		$this->options_data = get_option( $this->plugin_options, true );

	}

	/**
	 * Init plugin options data;
	 *
	 * @access public
	 * @var function
	 */
	function init() {

		$this->options_data = get_option( $this->plugin_options, true );

	}

	/**
	 * Update/add the plugin options.
	 *
	 * @access public
	 * @param array $data An array of plugin option.
	 * @var function
	 */
	public function save_options( $data = array() ) {

		$data_to_save = wp_json_encode( $data );

		if ( false !== $this->options_data ) {

			update_option( $this->plugin_options, $data_to_save );

		} else {

			add_option( $this->plugin_options, $data_to_save );

		}

		$this->options_data = $data;
	}

}
