<?php

declare(strict_types=1);

namespace frontend\modules\webcms;

use Yii;

/**
 * Website CMS module — completely separate from the main ERP backend.
 * Accessible at /webcms/  with its own session-based password login.
 */
class Module extends \yii\base\Module
{
    public $defaultRoute = 'default';

    /** Session key used to mark a logged-in CMS session. */
    public const SESSION_KEY = '_webcms_auth';

    public function init(): void
    {
        parent::init();
        $this->setAliases(['@webcms' => __DIR__]);
    }

    /** Returns the CMS password from params (falls back to a safe default). */
    public static function getPassword(): string
    {
        return Yii::$app->params['webcmsPassword'] ?? 'sjnutrizione@cms';
    }

    /** True if the current session has a valid CMS login. */
    public static function isLoggedIn(): bool
    {
        return (bool) Yii::$app->session->get(self::SESSION_KEY, false);
    }
}
