#ifndef SIGSUM_POLICY_INTERNAL_H_INCLUDED
#define SIGSUM_POLICY_INTERNAL_H_INCLUDED

#include <stdint.h>

#include "ascii.h"
#include "quorum.h"

/* When parsing an ASCII policy, names are represented as a list of
   definitions, see struct sigsum_policy_def below. Each definition
   refers to either a witness, a group, or the predefined name
   "none". */
enum sigsum_policy_def_type
  {
    SIGSUM_POLICY_DEF_NONE,
    SIGSUM_POLICY_DEF_WITNESS,
    SIGSUM_POLICY_DEF_GROUP,
  };

/* Represents a k-of-n group. Must have 1 <= threshold <=
   num_members. */
struct sigsum_policy_group
{
  size_t num_members;
  /* Elements are indices of *preceding* entries in the list of
     definitions. */
  size_t *members;
  size_t threshold;
};

/* Represent the definition of a name. */
struct sigsum_policy_def
{
  struct sigsum_buffer name;
  size_t bytecode_size;
  bool is_referenced;

  enum sigsum_policy_def_type type;
  union {
    /* For type SIGSUM_POLICY_DEF_WITNESS, index in witness list. */
    size_t witness_index;
    /* For type SIGSUM_POLICY_DEF_GROUP. */
    struct sigsum_policy_group group;
  };
};

/* Has the side effect of updates the byte_code size field, and
   sorting group members, hence defs not const. */
void
_sigsum_bytecode_compile_quorum (struct sigsum_quorum *quorum, struct sigsum_policy_def *defs,
				 size_t index);


#endif /* SIGSUM_POLICY_INTERNAL_H_INCLUDED */
