﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NeuroLedger"
           targetNamespace="http://waher.se/NL"
           elementFormDefault="qualified"
           xmlns="http://waher.se/NL"
           xmlns:mstns="http://waher.se/NL"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="getBlockReferences">
    <xs:annotation>
      <xs:documentation>Sent in an IQ get stanza to get block references from the destination.</xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:attribute name="last" type="xs:string" use="optional">
        <xs:annotation>
          <xs:documentation>Optional attribute referring to the last block reference received.</xs:documentation>
          <xs:documentation>The first block reference returned will be the first block reference immediately following this block reference.</xs:documentation>
        </xs:annotation>
      </xs:attribute>
      <xs:attribute name="max" type="xs:positiveInteger" use="optional">
        <xs:annotation>
          <xs:documentation>Maximum number of block references to return.</xs:documentation>
          <xs:documentation>The destination node might decide to lower the number of block references to return.</xs:documentation>
        </xs:annotation>
      </xs:attribute>
    </xs:complexType>
  </xs:element>

  <xs:element name="blockReferences">
    <xs:annotation>
      <xs:documentation>Response to a getBlockReferences request.</xs:documentation>
      <xs:documentation>Contains a sequence of block references.</xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="ref"/>
      </xs:sequence>
      <xs:attribute name="more" type="xs:boolean" use="optional" default="false">
        <xs:annotation>
          <xs:documentation>Lets the client requesting block references know if there are more block references available.</xs:documentation>
        </xs:annotation>
      </xs:attribute>
    </xs:complexType>
  </xs:element>

  <xs:element name="ref">
    <xs:annotation>
      <xs:documentation>Represents a block reference.</xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:complexContent>
        <xs:extension base="BlockEvent">
          <xs:attribute name="id" type="xs:string" use="required">
            <xs:annotation>
              <xs:documentation>The local ID of the block reference.</xs:documentation>
              <xs:documentation>These IDs are unique on the local machine only. When a node retrieves a block, it receives a new ID on that machine.</xs:documentation>
              <xs:documentation>The local ID is used for synchronization purposes.</xs:documentation>
            </xs:annotation>
          </xs:attribute>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:element>

  <xs:element name="ba" type="BlockEvent">
    <xs:annotation>
      <xs:documentation>Personal Event sent by a Neuro-Ledger, when a block has been added.</xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="bd" type="BlockEvent">
    <xs:annotation>
      <xs:documentation>Personal Event sent by a Neuro-Ledger, when a block has been deleted.</xs:documentation>
    </xs:annotation>
  </xs:element>
  
  <xs:complexType name="BlockEvent">
    <xs:attribute name="d" type="xs:base64Binary" use="required">
      <xs:annotation>
        <xs:documentation>Hash digest of block.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="s" type="xs:base64Binary" use="required">
      <xs:annotation>
        <xs:documentation>Digital signature of block, made by creator.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="l" type="xs:base64Binary" use="optional">
      <xs:annotation>
        <xs:documentation>Optional link to another block, in case block has been updated.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="cn" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>Name of collection in which the block resides.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="cr" type="xs:string" use="required">
      <xs:annotation>
        <xs:documentation>Identity of creator.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="ct" type="xs:dateTime" use="required">
      <xs:annotation>
        <xs:documentation>When block was created.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="u" type="xs:dateTime" use="optional">
      <xs:annotation>
        <xs:documentation>Timestamp when block was updated, if updated.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="x" type="xs:dateTime" use="optional">
      <xs:annotation>
        <xs:documentation>Timestamp when block expires, if it expires.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="t" type="BlockStatus" use="optional" default="Valid">
      <xs:annotation>
        <xs:documentation>Status of block.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="r" type="xs:anyURI" use="required">
      <xs:annotation>
        <xs:documentation>URL to block resource.</xs:documentation>
        <xs:documentation>When requesting information about the block from the resource, use the Accept header to define desired response encoding:</xs:documentation>
        <xs:documentation>application/octet-stream for a binary representation of the block suited for distribution to other nodes.</xs:documentation>
        <xs:documentation>text/xml for an XML Document response with embedded objects encoded in XML.</xs:documentation>
        <xs:documentation>application/json for a JSON Document response with embedded objects encoded in JSON.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
    <xs:attribute name="b" type="xs:unsignedLong" use="required">
      <xs:annotation>
        <xs:documentation>Size of block, in bytes.</xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:simpleType name="BlockStatus">
    <xs:annotation>
      <xs:documentation>Possible block states.</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="Valid">
        <xs:annotation>
          <xs:documentation>Block is claimed to be valid.</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="Updated">
        <xs:annotation>
          <xs:documentation>Block has been updated. Link points to updated block.</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="Deleted">
        <xs:annotation>
          <xs:documentation>Block hasbeen deleted.</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
    </xs:restriction>
  </xs:simpleType>
  
</xs:schema>
