<?php

namespace Config;

use App\Filters\JWTAuthFilter;
use App\Filters\LoginAuthFilter;
use App\Filters\ThrottlerFilter;
use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Filters\CSRF;
use CodeIgniter\Filters\DebugToolbar;
use CodeIgniter\Filters\Honeypot;

class Filters extends BaseConfig
{
    /**
     * Configures aliases for Filter classes to
     * make reading things nicer and simpler.
     *
     * @var array
     */
    public $aliases = [
        'csrf'     => CSRF::class,
        'toolbar'  => DebugToolbar::class,
        'honeypot' => Honeypot::class,
        'auth'     => JWTAuthFilter::class,
        'throttler'     => ThrottlerFilter::class,
        'login'     => LoginAuthFilter::class,
    ];

    /**
     * List of filter aliases that are always
     * applied before and after every request.
     *
     * @var array
     */
    public $globals = [
        'before' => [
            'login' => [
                'except' => [
                    'login',
                    'login/*',
                    'oauth',
                    'oauth/*',
                    'api',
                    'api/*',
                    'cron',
                    'cron/*',
                    'lang',
                    'lang/*',
                    'language',
                    'language/*',
                    'integration',
                    'integration/*'
                ]
            ],
            // 'honeypot',
            'csrf' => [
                'except' => [
                    'api',
                    'api/*'
                ]
            ],
        ],
        'after' => [
            'toolbar',
            // 'honeypot',
        ],
    ];

    /**
     * List of filter aliases that works on a
     * particular HTTP method (GET, POST, etc.).
     *
     * Example:
     * 'post' => ['csrf', 'throttle']
     *
     * @var array
     */
    public $methods = [
//        'get' => ['throttler'],
//        'post' => ['throttler']
    ];

    /**
     * List of filter aliases that should run on any
     * before or after URI patterns.
     *
     * Example:
     * 'isLoggedIn' => ['before' => ['account/*', 'profiles/*']]
     *
     * @var array
     */
    public $filters = [
        'auth' => [
            'before' => [
                'api/user/*',
                'api/user/'
            ],
        ],
        'throttler' => [
            'before' => [
                'api/*',
                'api/'
            ]
        ]
    ];
}
