<?php

namespace Nuwave\Lighthouse\Support\Compatibility;

use Laravel\Lumen\Application;
use Nuwave\Lighthouse\Support\Utils;

class LumenMiddlewareAdapter implements MiddlewareAdapter
{
    /**
     * @var \Laravel\Lumen\Application
     */
    protected $app;

    /**
     * Create a middleware adapter for Lumen applications.
     *
     * @param  \Laravel\Lumen\Application  $app
     * @return void
     */
    public function __construct(Application $app)
    {
        $this->app = $app;
    }

    /**
     * Get all of the defined middleware short-hand names.
     *
     * @return string[]
     */
    public function getMiddleware(): array
    {
        // TODO remove once Lumen gains public access to the middleware/routeMiddleware
        $globalMiddleware = Utils::accessProtected($this->app, 'middleware', []);
        $routeMiddleware = Utils::accessProtected($this->app, 'routeMiddleware', []);

        return array_merge($globalMiddleware, $routeMiddleware);
    }

    /**
     * Get all of the defined middleware groups.
     *
     * @return string[]
     */
    public function getMiddlewareGroups(): array
    {
        // Lumen doesn't have middleware groups
        return [];
    }
}
