/*
  This file is part of Anastasis
  Copyright (C) 2026 Anastasis SARL

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

  Anastasis 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 Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License along with
  Anastasis; see the file COPYING.LGPL.  If not, see <http://www.gnu.org/licenses/>
*/
/**
 * @file reducer/validation.c
 * @brief table of the national identity number validation functions
 * @author Christian Grothoff
 */
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
#include "validation.h"


/**
 * Mapping of a "validation-logic" name to its implementation.
 */
struct ValidationLogic
{
  /**
   * Name used in the redux.<cc>.json country files.
   */
  const char *name;

  /**
   * Function implementing the check.
   */
  ANASTASIS_ValidationLogic logic;
};


/**
 * All validation functions we support.  Every "validation-logic" value
 * appearing in contrib/redux.*.json must have an entry here; anything else is
 * rejected by #ANASTASIS_REDUX_validation_lookup_().
 */
static const struct ValidationLogic logics[] = {
  { "BE_NRN_check", &BE_NRN_check },
  { "CH_AHV_check", &CH_AHV_check },
  { "CZ_BN_check", &CZ_BN_check },
  { "DE_SVN_check", &DE_SVN_check },
  { "DE_TIN_check", &DE_TIN_check },
  { "ES_DNI_check", &ES_DNI_check },
  { "FR_INSEE_check", &FR_INSEE_check },
  { "IN_AADHAR_check", &IN_AADHAR_check },
  { "IT_CF_check", &IT_CF_check },
  { "NL_BSN_check", &NL_BSN_check },
  { "XX_SQUARE_check", &XX_SQUARE_check },
  { "XY_PRIME_check", &XY_PRIME_check },
  { NULL, NULL }
};


ANASTASIS_ValidationLogic
ANASTASIS_REDUX_validation_lookup_ (const char *name)
{
  if (NULL == name)
    return NULL;
  for (unsigned int i = 0; NULL != logics[i].name; i++)
    if (0 == strcmp (name,
                     logics[i].name))
      return logics[i].logic;
  return NULL;
}


/* end of validation.c */
