<?php

namespace CouponsPlus\App\Handlers;

use Carbon\Carbon;
use CouponsPlus\App\Plugin\InstalledVersion;
use CouponsPlus\App\Plugin\InstalledVersions;
use CouponsPlus\App\Time\WpDateTimeZone;
use CouponsPlus\Original\Events\Handler\EventHandler;

Class InstalledVersionManagerHandler extends EventHandler
{
    protected $numberOfArguments = 1;
    protected $priority = 10;

    public function execute()
    {
        (object) $installedVersions = new InstalledVersions;

        if (!$installedVersions->hasCurrentVersion()) {
            $installedVersions->add(new InstalledVersion(
                $installedVersions->getCurrentVersion(), 
                Carbon::now(WpDateTimeZone::getWpTimezone())->format(InstalledVersion::DATE_FORMAT)
            ));

            $installedVersions->save();
        }
    }
}