<?php

namespace MediaTrim;

use MediaTrim\Core\Enqueues;
use MediaTrim\Admin\Admin;
use MediaTrim\Core\Cleaner;
use MediaTrim\Core\Trash;
use MediaTrim\Core\FileSystemScanner;
use MediaTrim\Core\ScanManager;
use MediaTrim\Core\StockManager;
use MediaTrim\Core\SettingsManager;

defined('ABSPATH') || exit;

/**
 * Class Plugin
 *
 * Main plugin class for Media Image Cleaner.
 *
 * @package MediaTrim
 */
final class Plugin
{

    /**
     * Plugin version
     *
     * @var string
     */
    const VERSION = '1.0.3';

    /**
     * Plugin slug
     *
     * @var string
     */
    const SLUG = 'media-trim';

    /**
     * Plugin prefix
     *
     * @var string
     */
    const PREFIX = 'mtrim_';

    /**
     * Plugin text domain
     *
     * @var string
     */
    const TEXT_DOMAIN = 'media-trim';

    /**
     * Plugin instance
     *
     * @var Plugin|null
     */
    private static $instance = null;

    /**
     * Constructor
     */
    private function __construct()
    {
        $this->define_constants();
        $this->init_hooks();
    }

    /**
     * Get plugin instance
     *
     * @return Plugin
     */
    public static function get_instance()
    {
        if (null === self::$instance) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * Define constants
     */
    private function define_constants()
    {
        if (!defined('MTRIM_SLUG')) define('MTRIM_SLUG', self::SLUG);
        if (!defined('MTRIM_PREFIX')) define('MTRIM_PREFIX', self::PREFIX);
        if (!defined('MTRIM_TEXT_DOMAIN')) define('MTRIM_TEXT_DOMAIN', self::TEXT_DOMAIN);
        if (!defined('MTRIM_PLUGIN_PATH')) define('MTRIM_PLUGIN_PATH', plugin_dir_path(MTRIM_PLUGIN_FILE));
        if (!defined('MTRIM_PLUGIN_URL')) define('MTRIM_PLUGIN_URL', plugin_dir_url(MTRIM_PLUGIN_FILE));
        if (!defined('MTRIM_PLUGIN_BASENAME')) define('MTRIM_PLUGIN_BASENAME', plugin_basename(MTRIM_PLUGIN_FILE));
    }


    /**
     * Initialize hooks
     */
    private function init_hooks()
    {
        add_action('plugins_loaded', [$this, 'init_plugin']);
    }

    /**
     * Initialize plugin
     */
    public function init_plugin()
    {
        Enqueues::get_instance();
        Admin::get_instance();
        Cleaner::get_instance();
        Trash::get_instance();
        FileSystemScanner::get_instance();
        ScanManager::get_instance();
        StockManager::get_instance();
        SettingsManager::get_instance();
    }
}