/*
 * This file is part of the Poliqarp suite.
 * 
 * Copyright (C) 2009, 2010 by Instytut Podstaw Informatyki Polskiej
 * Akademii Nauk (IPI PAN; Institute of Computer Science, Polish
 * Academy of Sciences; cf. www.ipipan.waw.pl).  All rights reserved.
 * 
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file gpl.txt included in the packaging
 * of this file.  (See http://www.gnu.org/licenses/translations.html for
 * unofficial translations.)
 * 
 * A commercial license is available from IPI PAN (contact
 * Michal.Ciesiolka@ipipan.waw.pl or ipi@ipipan.waw.pl for more
 * information).  Licensees holding a valid commercial license from IPI
 * PAN may use this file in accordance with that license.
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

#ifndef BPNG_META_KEY_H
#define BPNG_META_KEY_H 1

#include <bp/ng/list.h>

#include <sakura/abi.h>
#include <sakura/common/hash-table.h>

/**
 * A metadata type.
 */
enum meta_type {
   META_TYPE_STRING,
   META_TYPE_ENUM,
   META_TYPE_DATE
};

/**
 * A metadata key.
 */
struct meta_key {
   struct list names;
   enum meta_type type;
   struct list paths;
   struct hash_table values;
   bool multiple;
   bool required;
   const struct list *xmlns;
};

/**
 * Initialze the metadata key.
 */
void meta_key_create(struct meta_key *);

/**
 * Destroy the metadata key.
 */
void meta_key_destroy(struct meta_key *);

/**
 * Destroy the metadata key and free the allocated memory.
 */
void meta_key_free(void *meta_key);

/**
 * Extend the set of the possible values for the metadata key.
 */
void meta_key_add_value(struct meta_key *, const char *value);

/**
 * Check if the set of the possible values for the metadata key contains the
 * given value.
 */
bool meta_key_has_value(struct meta_key *, const char *value);

/**
 * Validate if all the required metadata key fields has been provided and are
 * consistent.
 *
 * @return 0 in the metadata key is valid, -1 otherwise
 */
int meta_key_validate(const struct meta_key *);

/**
 * Get a name of the key.
 *
 * @return a name, or NULL on error
 */
const char* meta_key_get_name(const struct meta_key *);

#endif
