/* @flow */

/**
 * @name iterator:
 */
export type iterator = Object;

/**
 * @name zone_id:
 */
export type zone_id = (number | String);

/**
 * @name word_index_item:
 */
export type word_index_item = [
  string, /* word */
  number, /* offset */
  number, /* length */
  number, /* ordinal */
  ?Object /* extra */
];

/**
 * @name tag_index_item:
 */
export type tag_index_item = [
  string, /* word */
  word_index_item
];

/**
 * @name link_index_item:
 */
export type link_index_item = [
  zone_id, /* zone_id */
  string,  /* index_id */
  number,  /* offset */
  number,  /* length */
  string,  /* target_node_id */
];

/**
 * @name document_stub:
 */
export type document_stub = {
  _id: string,
  _rev: string
};

/**
 * @name node_input:
 */
export type node_input = {
  type: ?'node',
  title: string,
  content: string,
  zone_id: ?zone_id,
  data_type: ?string,
  tags: ?Array<string>
};

/**
 * @name node:
 */
export type node = document_stub & node_input & {
  index_id: string
};

/**
 * @name index:
 */
export type index = document_stub & {
  type: 'index',
  node_id: string,
  data: {
    content: string,
    words: Array<word_index_item>,
    tags: Array<tag_index_item>
  },
  links: ?Array<[
    zone_id, string, string, number, number,
      Array<word_index_item>
  ]>
};

/**
 * @name node_stub:
 */
export type node_stub = document_stub & {
  type: 'node'
};

/**
 * @name index_stub:
 */
export type index_stub = document_stub & {
  type: 'index'
};

/**
 * @name node_and_index:
 */
export type node_and_index = {
  node: node,
  index: index
};

/**
 * @name splitter_result:
 */
export type splitter_result = {
  content: ?string,
  tags: Array<tag_index_item>,
  words: Array<word_index_item>
};

