<?php
namespace Avirtum\GutenDraw;

defined( 'ABSPATH' ) || exit;

class Plugin {
    public const OPTION_VERSION = '_gutendraw_version';
    public const OPTION_DATE = '_gutendraw_date';

    public function run() {
        self::updateVersion();
        self::updateDate();

        add_action( 'plugins_loaded', [ $this, 'pluginLoaded' ] );
    }

    private function updateVersion() {
        if ( version_compare( get_option( self::OPTION_VERSION ), GUTENDRAW_PLUGIN_VERSION, '<' ) ) {
            update_option( self::OPTION_VERSION, GUTENDRAW_PLUGIN_VERSION );
        }
    }

    private function updateDate() {
        if ( !get_option( self::OPTION_DATE ) ) {
            update_option( self::OPTION_DATE, time() );
        }
    }

    public function pluginLoaded() {
        new System\I18n();
        new Rest\Routes();
        new Blocks\ImageBlock();
        new System\Shortcode();
        new System\Feedback();
        new System\Admin();
    }
}