<?php
namespace GriffinForms\Includes\Schedulers;

use GriffinForms\Traits\Singleton;

class EmailScheduler
{
    use Singleton;

    public function register()
    {
        add_action('griffinforms_send_autoresponder', [$this, 'handleAutoresponder'], 10, 2);
        add_action('griffinforms_send_admin_alert', [$this, 'handleAdminAlert'], 10, 2);
    }

    /**
     * Handles scheduled autoresponder processing.
     *
     * @param array $data
     * @param array $mappings
     */
    public function handleAutoresponder($data, $mappings)
    {
        $handler = new \GriffinForms\Frontend\Actions\PostSubmission($data);
        $handler->processUserAutoresponderMappings($mappings);
    }

    /**
     * Handles scheduled admin email alert processing.
     *
     * @param array $data
     * @param array $alert_emails
     */
    public function handleAdminAlert($data, $alert_emails)
    {
        $handler = new \GriffinForms\Frontend\Actions\PostSubmission($data);
        $handler->alert_emails = $alert_emails;
        $handler->processAdminEmailAlert();
    }
}