<?php

namespace PortalPeople\cart;

use Yii;
use yii\base\BootstrapInterface;
use yii\base\Module as BaseModule;
use yii\console\Application as ConsoleApplication;

class Module extends BaseModule implements BootstrapInterface
{
    public $defaultRoute = 'config/index';
    public $controllerNamespace = 'PortalPeople\\cart\\controllers';

    public bool $enabled = true;

    public function bootstrap($app): void
    {
        $this->id = 'cart';

        if (!isset($app->getModules()[$this->id])) {
            $app->setModule($this->id, $this);
        }

        if (!($app instanceof ConsoleApplication) && isset($app->urlManager)) {
            $app->urlManager->addRules([
                "api/{$this->id}/<controller:[\\w\\-]+>/<action:[\\w\\-]+>" => "{$this->id}/api/<controller>/<action>",
                "{$this->id}/<action:[\\w\\-]+>" => "{$this->id}/config/<action>",
                "{$this->id}/<controller:[\\w\\-]+>/<action:[\\w\\-]+>" => "{$this->id}/<controller>/<action>",
            ], false);
        }
    }

    public function init(): void
    {
        parent::init();
    }
}
