<?php

namespace CarDealerPress\includes\functions;

use CarDealerPress\admin\functions\Main;

use CarDealerPress\includes\admin\{Admin_Settings_Page, Shortcode_Settings_Page, Theme_Settings_Page};
use CarDealerPress\includes\database\{Alter_Tables};
use CarDealerPress\Includes\Cron\Cron;
use CarDealerPress\includes\helpers\CheckRequirements;
use CarDealerPress\includes\init\{Admin_Assets};

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
class CarDealerPress {
	use Logger;
	public function run() {
		$this->create_log_file_if_not_exist();
		$cron = new Cron();
		$cron->init_refresh_log_file();
		$cron->init_cron_company_handler();
		$cron->company_handler_backup_transient_refresh();
		$this->check_requirements();
		new Admin_Settings_Page();
		new Theme_Settings_Page();
		new Shortcode_Settings_Page();
		new Admin_Assets();
		new Main();
		new Alter_Tables();
		new Show_Theme();
		// new Router(); # TODO: Future, routing currently in Main
		new Shortcode();
	}

	function check_requirements() {
		$requirements = new CheckRequirements();
		if ( $requirements->has_been_checked() === false ) {
			$requirements->set_master_file( __FILE__ );
			if ( $requirements->check_requirements() === false ) {
				return false;
			}
		}
	}

	function create_log_file_if_not_exist() {
		global $wp_filesystem;
		include_once ABSPATH . 'wp-admin/includes/file.php';
		$date      = wp_date( 'Y-m-d H:i:s' );
		$message   = "[$date]: Log file created<br>";
		WP_Filesystem();
		if ( ! is_file( CDP_LOGS ) ) {
			$wp_filesystem->put_contents(CDP_LOGS, $message );
		}
	}



}
