/*
   This file is part of Challenger
   Copyright (C) 2023 Taler Systems SA

   Challenger is free software; you can redistribute it and/or modify it under the
   terms of the GNU General Public License as published by the Free Software
   Foundation; either version 3, or (at your option) any later version.

   Challenger is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along with
   Challenger; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
/**
 * @file src/include/challenger-database/get_validation_pkce.h
 * @brief implementation of the get_validation_pkce function for Postgres
 * @author Bohdan Potuzhnyi
 * @author Vlada Svirsh
 */
#ifndef CHALLENGER_DATABASE_GET_VALIDATION_PKCE_H
#define CHALLENGER_DATABASE_GET_VALIDATION_PKCE_H

#include <taler/taler_util.h>
#include <taler/taler_json_lib.h>
#include "challenger_util.h"
#include "challenger_database_lib.h"


/**
 * Return validation details.  Used by the ``/token`` endpoint to check the
 * authorization code and the PKCE binding before minting an access token.
 *
 * Only returns validations that were actually *solved* (the user entered the
 * correct PIN); an unsolved, expired or foreign validation is reported as
 * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS.  The predicate must stay in sync with
 * the one in CHALLENGERDB_do_insert_token().
 *
 * @param cls
 * @param nonce unique nonce to use to identify the validation
 * @param client_id serial id of the authenticated client redeeming the code
 * @param[out] client_secret set to secret of client (for client that setup the challenge)
 * @param[out] address set to client-provided address
 * @param[out] client_scope set to OAuth2 scope
 * @param[out] client_state set to client state
 * @param[out] client_redirect_uri set to client redirect URL
 * @param[out] code_challenge set to PKCE code challenge
 * @param[out] code_challenge_method set to PKCE code challenge method enum
 * @return transaction status:
 *   #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if the nonce was found and solved
 *   #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if we do not know the nonce, it
 *     expired, it belongs to another client or it was never solved
 *   #GNUNET_DB_STATUS_HARD_ERROR on failure
 */
enum GNUNET_DB_QueryStatus
CHALLENGERDB_get_validation_pkce (
  struct CHALLENGERDB_PostgresContext *ctx,
  const struct CHALLENGER_ValidationNonceP *nonce,
  uint64_t client_id,
  char **client_secret,
  json_t **address,
  char **client_scope,
  char **client_state,
  char **client_redirect_uri,
  char **code_challenge,
  uint32_t *code_challenge_method);

#endif
