<?php

declare(strict_types=1);

namespace MyCustomizer\WooCommerce\Connector\Factory;

use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

define('MCZR_VIEWS_DIR', realpath(__DIR__ . '/../views'));
define('MCZR_PLUGIN_VIEW_DIR', realpath(__DIR__ . '/../'));
define('MCZR_TRANSLATION_DIR', MCZR_PLUGIN_VIEW_DIR . '/Resources/translations');

class MczrFactory
{
    /** @var self */
    private static $instance;
    /** @var Environment */
    private $twig;
    /** @var ValidatorInterface */
    private $validator;

    public function __construct()
    {
        $this->validator = Validation::createValidator();
        $this->twig = new Environment(
            new FilesystemLoader([
                MCZR_VIEWS_DIR,
                MCZR_PLUGIN_VIEW_DIR . '/Resources/views',
            ])
        );
    }

    public static function getInstance(): self
    {
        if (!isset(self::$instance)) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    public function getValidator(): ValidatorInterface
    {
        return $this->validator;
    }

    public function getTwig(): Environment
    {
        return $this->twig;
    }
}
