<?php

namespace Authstack\OpenIDConnect\Model\Protocol\Flow;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Authstack\OpenIDConnect\Client;
use Authstack\OpenIDConnect\Provider;
use Illuminate\Http\RedirectResponse;

interface FlowInterface
{
    /**
     * Builds the querystring and prepares everything needed for redirecting to OpenID Provider, from urls to nonce
     *
     * @param Provider $provider
     * @param Client $client
     * @return FlowInterface
     */
    public function build(Provider $provider, Client $client): FlowInterface;

    /**
     * Uses the data built by build() method and returns the HTTP response object
     *
     * @param Provider $provider
     * @param Client $client
     * @return RedirectResponse
     */
    public function authenticate(Provider $provider, Client $client): RedirectResponse;

    /**
     * Consumes the OpenID Provider response and performs code exchange (depending on the flow) + runs the response
     * through security measures before returning the response
     *
     * @param Provider $provider
     * @param Client $client
     * @param Request $request
     * @return array
     */
    public function consume(Provider $provider, Client $client, Request $request): array;

    /**
     * Returns an array of parameters that will be placed in querystring when requesting authentication
     *
     * @return array
     */
    public function getQuery(): array;

    /**
     * Returns the redirect URI (including parameters) used to authenticate against OP
     *
     * @return Response
     */
    public function getRedirectURI(): ?string;
}