<?php
/**
 * @package   Essentials YOOtheme Pro 2.3.4 build 0217.0955
 * @author    ZOOlanders https://www.zoolanders.com
 * @copyright Copyright (C) Joolanders, SL
 * @license   http://www.gnu.org/licenses/gpl.html GNU/GPL
 */

namespace ZOOlanders\YOOessentials\Form\Action;

use Exception;

class ActionConfigurationException extends Exception
{
    private Action $action;

    public static function create(Action $action, string $error, ?Exception $previous = null): self
    {
        $actionName = (new \ReflectionClass($action))->getShortName();
        $message = "{$actionName} configuration error: {$error}";

        return (new ActionConfigurationException($message, $previous ? $previous->getCode() : 0, $previous))
            ->forAction($action);
    }

    public function forAction(Action $action): self
    {
        $this->action = $action;

        return $this;
    }

    public function action(): Action
    {
        return $this->action;
    }
}
