<?php

namespace portalpeople\stripe;

use yii\base\BootstrapInterface;
use yii\base\Module as BaseModule;

class Module extends BaseModule implements BootstrapInterface
{
    public string $moduleId = 'stripe';
    public string $secretKey = '';
    public string $webhookSigningSecret = '';
    public string $apiBaseUrl = 'https://api.stripe.com/v1';
    public ?string $stripeVersion = null;
    public int $timeout = 30;
    public int $webhookTolerance = 300;
    public bool $debug = false;

    public $controllerNamespace = 'portalpeople\stripe\controllers';

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

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

        if ($app->has('urlManager')) {
            $app->urlManager->addRules([
                "{$this->id}/api/<action:[\\w\\-]+>" => "{$this->id}/api/<action>",
                "{$this->id}/webhook/<action:[\\w\\-]+>" => "{$this->id}/webhook/<action>",
                "{$this->id}/hostedpage/<action:[\\w\\-]+>" => "{$this->id}/hostedpage/<action>",
                "{$this->id}/config/<action:[\\w\\-]+>" => "{$this->id}/config/<action>",
            ], false);
        }
    }
}
