<?php

$config = [
    'id' => 'skillparts',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'aliases' => [
        '@vendor'       => dirname(__DIR__) . '/../../../vendor',
        '@bower'        => '@vendor/bower-asset',
        '@npm'          => '@vendor/npm-asset'
    ],
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => '',
            'baseUrl' => ''
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\Account',
            'loginUrl'          => ['/authentication'],
            'enableAutoLogin'   => true
        ],
        // 'session' => [
        //     'class' => 'yii\web\Session',
        //     'cookieParams' => ['lifetime' => 3600 * 24 * 30 * 12],
        //     'timeout' => 3600 * 24 * 30 * 12,
        //     'useCookies' => true,
        // ],
        'errorHandler' => [
            'errorAction' => 'error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'arangodb' => require __DIR__ . '/db.php',
        'urlManager' => [
            'enablePrettyUrl'   => true,
            'showScriptName'    => false,
            'rules' => [
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => 'main'
                ],
                'product/<id:\d+>' => 'product/index'
            ],
        ],

    ],
    'modules' => [
        'exchange' => [
            'class' => 'carono\exchange1c\ExchangeModule',
            'groupClass' => 'app\models\SupplyGroup',
            'productClass' => 'app\models\Supply',
            'offerClass' => 'app\models\SupplyEdgeProduct',
            'partnerClass' => 'app\models\Account',
            'documentClass' => 'app\models\Purchase',
            'auth' => function ($mail, $pswd) {
                // Необходимо уничтожить AccountForm
                // return (new \app\models\AccountForm())->authentication($mail, $pswd);

                if ($user = \app\models\Account::findByMail($mail)) {
                    if ($user->validatePassword($pswd)) {
                        return $user;
                    }
                }
                return false;
            }
        ]
    ],
    'params' => require __DIR__ . '/params.php',
];

if (YII_ENV_DEV) {
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        'panels' => [
            'ArangoDB' => [
                'class' => 'mirzaev\yii2\arangodb\panels\arangodb\ArangoDbPanel'
            ]
        ]
    ];
}

return $config;