<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="http://zesty.ca/pfif/1.2"
           targetNamespace="http://zesty.ca/pfif/1.2"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified">

  <!-- The PFIF document. -->

  <xs:element name="pfif">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="person" type="Person"/>
        <xs:element name="note" type="Note"/>
      </xs:choice>
    </xs:complexType>
    <xs:key name="person_record_id">
      <xs:selector xpath=".//person"/>
      <xs:field xpath="person_record_id"/>
    </xs:key>
    <xs:key name="note_record_id">
      <xs:selector xpath=".//note"/>
      <xs:field xpath="note_record_id"/>
    </xs:key>
  </xs:element>

  <!-- The <person> element. -->

  <xs:complexType name="Person">
    <xs:annotation>
      <xs:documentation>A record about a missing or found person.</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="person_record_id" type="xs:string">
        <xs:annotation>
          <xs:documentation>Unique identifier for this record, which consists of a domain name followed by a slash and a local identifier. The domain name identifies this record's home repository, which is the authority for this record. The format of the local identifier is up to the home repository. When the person_record_id begins with a domain other than the application's own domain, it means this record is a clone of a record from another source.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:group ref="PersonFields"/>
      <xs:element name="note" type="NestedNote" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <!-- Fields that can appear in any order in a <person>. -->

  <xs:group name="PersonFields">
    <xs:all>
      <xs:element name="entry_date" type="UtcDateTime" minOccurs="0">
        <xs:annotation>
          <xs:documentation>(string in the form "yyyy-mm-ddThh:mm:ssZ"): Date in UTC that this record was stored in the local application (not the date of creation in the home repository). The application must guarantee that this value increases monotonically so that a client can update a copy of a database by querying for all records with an entry_date greater than or equal to the entry_date of the last received record.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="author_name" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The full name of the person who entered this record.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="author_email" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The preferred contact e-mail address of the person who entered this record.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="author_phone" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The preferred contact phone number of the person who entered this record.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="source_name" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The name of the home repository of this record.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="source_date" type="UtcDateTime" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The date in UTC that the record was originally created in its home repository.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="source_url" type="xs:anyURI" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The URL to the record in the home repository (as specific as possible, down to the URL of the individual record).</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="first_name" type="xs:string">
        <xs:annotation>
          <xs:documentation>(string, all capitals, no accents): 
           First name of the person sought or found, optionally followed by a space and any middle names or middle initials. </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="last_name" type="xs:string">
        <xs:annotation>
          <xs:documentation>(string, all capitals, no accents): Last name of the person sought or found.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="sex" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The sex of the person sought or found.</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:enumeration value="female"/>
            <xs:enumeration value="male"/>
            <xs:enumeration value="other"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="date_of_birth" type="ApproximateDate" minOccurs="0">
        <xs:annotation>
          <xs:documentation>Exact date of birth (in YYYY-MM-DD format) or approximate date of birth (in YYYY-MM format or YYYY format) of the person sought or found.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="age" type="ApproximateInteger" minOccurs="0">
        <xs:annotation>
          <xs:documentation>Age of the person sought or found, as of the source_date of this record. The value of this field is either a single decimal integer, or an inclusive range given as two decimal integers separated by a hyphen. This field has no defined meaning when source_date is missing.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="home_street" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>(string, all capitals, no accents): Street name (no number) of the home address of the person sought or found.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="home_neighborhood" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>(string, all capitals, no accents): Name of the home neighborhood of the person sought or found.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="home_city" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>(string, city name, all capitals, no accents): Home city of the person sought or found.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="home_state" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>(string, two-letter postal abbreviation): Home state of the person sought or found.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="home_postal_code" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>Postal code of the home address of the person sought or found.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="home_country" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>Two-letter uppercase ISO 3166-1 country code of the home address of the person sought or found.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="photo_url" type="xs:anyURI" minOccurs="0">
        <xs:annotation>
          <xs:documentation>URL to an image of an identifying photograph of the person sought or found.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="other" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
Free-form text containing any other static data fields brought in from other sources. (Non-static data imported from other sources should go into a note record.) Short fields should be on a single line with the field name, a colon, and the field value. Long fields can be given as a line with the field name and a colon, then text indented on the following lines. When a record is converted from some other form to PFIF by a machine process, the field "automated-record-creator" should be present and should name the program that produced the PFIF. A description of the person in free-form text can also go here, with the field name "description". For example:

description:
    Dark hair, in her late thirties.
    Also goes by the names "Kate" or "Katie".
automated-record-creator: ScrapeMatic 0.5

Field names for data imported from other applications should begin with the domain name and a slash. For example, if a birthdate is imported from an ICRC record, it might look like this:

icrc.org/birthdate: 1976-02-26
          </xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:all>
  </xs:group>

  <!-- The <note> element. -->

  <xs:complexType name="Note">
    <xs:annotation>
      <xs:documentation>A timestamped note about a particular missing or found person.  This type describes stand-alone note elements, which must specify the person_record_id of the person element to which they belong.  The parent person element need not be present in the same document as the note.</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="note_record_id" type="xs:string">
        <xs:annotation>
          <xs:documentation>Unique identifier for this record, which consists of a domain name followed by a slash and a local identifier. The domain name identifies this record's home repository, which is the authority for this record. The format of the local identifier is up to the home repository. When the note_record_id begins with a domain other than the application's own domain, it means this record is a clone of a record from another source.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="person_record_id" type="xs:string">
        <xs:annotation>
          <xs:documentation>The person_record_id of the person record to which this note belongs.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:group ref="NoteFields"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="NestedNote">
    <xs:annotation>
      <xs:documentation>A timestamped note about a particular missing or found person.  This type describes note elements nested within person elements, which may or may not specify the person_record_id of the person record to which they belong.</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="note_record_id" type="xs:string">
        <xs:annotation>
          <xs:documentation>Unique identifier for this record, which consists of a domain name followed by a slash and a local identifier. The domain name identifies this record's home repository, which is the authority for this record. The format of the local identifier is up to the home repository. When the note_record_id begins with a domain other than the application's own domain, it means this record is a clone of a record from another source.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="person_record_id" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The person_record_id of the person record to which this note belongs.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:group ref="NoteFields"/>
    </xs:sequence>
  </xs:complexType>

  <!-- Fields that can appear in any order in a <note> element. -->

  <xs:group name="NoteFields">
    <xs:all>
      <xs:element name="linked_person_record_id" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The person_record_id of another person record which this note claims to be for the same person as this note's person record.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="entry_date" type="UtcDateTime" minOccurs="0">
        <xs:annotation>
          <xs:documentation>(string in the form "yyyy-mm-ddThh:mm:ssZ"): Date in UTC that this record was stored in the local application (not the date of creation in the home repository). The application must guarantee that this value increases monotonically so that a client can update a copy of a database by querying for all records with an entry_date greater than or equal to the entry_date of the last received record.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="author_name" type="xs:string">
        <xs:annotation>
          <xs:documentation>The full name of the person who entered this note.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="author_email" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The preferred contact e-mail address of the person who entered this note.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="author_phone" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The preferred contact phone number of the person who entered this note.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="source_date" type="UtcDateTime">
        <xs:annotation>
          <xs:documentation>(string in the form "yyyy-mm-ddThh:mm:ssZ"): The date in UTC that this note was originally created in its home repository. In most cases, notes should be sorted by this field for display.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="status" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The status of the person sought or found.</xs:documentation>
        </xs:annotation>
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:enumeration value="information_sought">
              <xs:annotation>
                <xs:documentation>The author of this note is seeking information on the person in question.</xs:documentation>
              </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="is_note_author">
              <xs:annotation>
                <xs:documentation>The author of this note is the person in question.</xs:documentation>
              </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="believed_alive">
              <xs:annotation>
                <xs:documentation>The author of this note has received information that the person in question is alive.</xs:documentation>
              </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="believed_missing">
              <xs:annotation>
                <xs:documentation>The author of this note has reason to believe that the person in question is still missing.</xs:documentation>
              </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="believed_dead">
              <xs:annotation>
                <xs:documentation>The author of this note has received information that the person in question is dead.</xs:documentation>
              </xs:annotation>
            </xs:enumeration>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="found" type="xs:boolean" minOccurs="0">
        <xs:annotation>
          <xs:documentation>True if the missing person has been personally contacted or seen, or false otherwise. The text field of this note should describe HOW and WHEN the person was contacted or seen.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="email_of_found_person" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The preferred contact e-mail address of the FOUND person. This field is present ONLY if the person has been FOUND. The text field of this note should describe HOW the person's contact information was determined. </xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="phone_of_found_person" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>The preferred contact phone number of the FOUND person. This field is present ONLY if the person has been FOUND. The text field of this note should describe HOW the person's contact information was determined.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="last_known_location" type="xs:string" minOccurs="0">
        <xs:annotation>
          <xs:documentation>A free-form description of the last known location of the person being sought, including the city, state, and as much detail as possible. The text field of this note should describe HOW the person's location was determined.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="text" type="xs:string">
        <xs:annotation>
          <xs:documentation>Free-form text description of the person's current condition, situation and location details, where they were last seen, corrections to other information, etc.</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:all>
  </xs:group>
  <xs:simpleType name="UtcDateTime">
    <xs:annotation>
      <xs:documentation>A dateTime in UTC.</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:dateTime">
      <xs:pattern value=".*Z"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="ApproximateInteger">
    <xs:annotation>
      <xs:documentation>A single decimal integer or an inclusive range given as two integers separated by a hyphen.</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9]+(-[0-9]+)?"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="ApproximateDate">
    <xs:annotation>
      <xs:documentation>An exact or approximate Gregorian date in YYYY, YYYY-MM, or YYYY-MM-DD format.</xs:documentation>
    </xs:annotation>
    <xs:union memberTypes="xs:gYear xs:gYearMonth xs:date"/>
  </xs:simpleType>
</xs:schema>
