<?php

declare(strict_types=1);

namespace App\Modules\Identity\Controllers;

use App\Modules\Identity\Services\AuthService;

class LoginController
{
    public function __construct(private readonly AuthService $authService)
    {
    }

    public function show(): array
    {
        return [
            'view' => 'auth.login',
            'data' => [
                'title' => 'Anmeldung',
                'providers' => $this->authService->availableProviders(),
                'oidcProviders' => $this->authService->configuredOidcProviders(),
                'loginPreview' => $this->authService->centralLoginPreview(),
                'identityPolicy' => $this->authService->identityPolicy(),
                'roleMatrix' => $this->authService->roleMatrix(),
            ],
        ];
    }

    public function authenticate(array $payload): array
    {
        return $this->authService->attemptLogin($payload);
    }
}
