<?xml version="1.0" encoding="UTF-8"?>
<!--
  kiosk-feed/1 — the feed an Intelibo Kiosk screen reads.

  This schema is the contract. The human guide's element reference is generated from the
  <xs:documentation> below (tools/gen-docs.py), so the two cannot disagree; change the words
  here, not in the guide.

  It is deliberately lax where screens are: elements and attributes from other namespaces are
  allowed anywhere, so a CMS can carry its own data alongside, and screens ignore what they do
  not know. What it pins down is what screens rely on.

  Frozen: a new optional element or attribute may still be added to /1. Renaming or removing
  anything, or changing what it means, is kiosk-feed/2, in a new namespace.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:k="urn:intelibo:kiosk-feed:1"
           targetNamespace="urn:intelibo:kiosk-feed:1"
           elementFormDefault="qualified">

  <xs:element name="kiosk-feed">
    <xs:annotation><xs:documentation>The root. Its namespace, urn:intelibo:kiosk-feed:1, is the version.</xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="k:source" minOccurs="0"/>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element ref="k:item"/>
          <xs:element ref="k:playlist"/>
          <xs:any namespace="##other" processContents="lax"/>
        </xs:choice>
      </xs:sequence>
      <xs:attribute name="generated" type="xs:dateTime">
        <xs:annotation><xs:documentation>When your CMS built the feed. Screens record it, which helps when diagnosing a feed that stopped changing.</xs:documentation></xs:annotation>
      </xs:attribute>
      <xs:attribute name="ttl" type="xs:positiveInteger">
        <xs:annotation><xs:documentation>Your suggested poll interval, in seconds. Advisory: screens poll on their template's schedule, every 5 minutes unless it says otherwise.</xs:documentation></xs:annotation>
      </xs:attribute>
      <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:complexType>
    <xs:unique name="item-ids">
      <xs:selector xpath="k:item"/>
      <xs:field xpath="@id"/>
    </xs:unique>
  </xs:element>

  <xs:element name="source">
    <xs:annotation><xs:documentation>Who publishes the feed.</xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:attribute name="name" type="xs:string">
        <xs:annotation><xs:documentation>The organisation's name, as a screen may show it.</xs:documentation></xs:annotation>
      </xs:attribute>
      <xs:attribute name="url" type="xs:anyURI">
        <xs:annotation><xs:documentation>The organisation's web site.</xs:documentation></xs:annotation>
      </xs:attribute>
      <xs:attribute name="timezone" type="xs:string">
        <xs:annotation><xs:documentation>An IANA timezone, e.g. America/New_York: the zone your dates mean when they are shown.</xs:documentation></xs:annotation>
      </xs:attribute>
      <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="item">
    <xs:annotation><xs:documentation>One thing a screen can show: an event, a news story, a picture, a programme, a sponsor, a notice.</xs:documentation></xs:annotation>
    <xs:complexType>
      <!-- Any order, as screens read it. XSD 1.0 cannot say "exactly one title, anywhere, among
           repeatable siblings", so title's being required is checked by the validator, which
           runs the screens' own parser. -->
      <xs:sequence>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="title" type="k:text120">
            <xs:annotation><xs:documentation>Required. Plain text; screens show at most 120 characters.</xs:documentation></xs:annotation>
          </xs:element>
          <xs:element name="subtitle" type="xs:string">
            <xs:annotation><xs:documentation>A short line under the title, e.g. a tile's "Folk dance · Choir · Traditions".</xs:documentation></xs:annotation>
          </xs:element>
          <xs:element name="starts" type="xs:dateTime">
            <xs:annotation><xs:documentation>When an event begins, with a UTC offset: 2026-09-20T18:00:00-04:00. An event needs it: screens keep an event without one, but no template can place it.</xs:documentation></xs:annotation>
          </xs:element>
          <xs:element name="ends" type="xs:dateTime">
            <xs:annotation><xs:documentation>When an event ends. With a UTC offset.</xs:documentation></xs:annotation>
          </xs:element>
          <xs:element name="published" type="xs:dateTime">
            <xs:annotation><xs:documentation>When a story was published, with a UTC offset. A news item needs it to be sorted among the others.</xs:documentation></xs:annotation>
          </xs:element>
          <xs:element name="location" type="xs:string">
            <xs:annotation><xs:documentation>Where an event happens, as plain text.</xs:documentation></xs:annotation>
          </xs:element>
          <xs:element name="category" type="xs:string">
            <xs:annotation><xs:documentation>A short label; the stage shows it as a chip.</xs:documentation></xs:annotation>
          </xs:element>
          <xs:element name="sponsor" type="xs:string">
            <xs:annotation><xs:documentation>Who an ad is for, as plain text.</xs:documentation></xs:annotation>
          </xs:element>
          <xs:element name="body" type="k:body">
            <xs:annotation><xs:documentation>Longer text. format="markdown" (the default is "text") allows paragraphs, bullet lists, bold, italics and line breaks; headings show as plain text, links show their words only, and HTML is shown as text.</xs:documentation></xs:annotation>
          </xs:element>
          <xs:element name="image" type="k:image">
            <xs:annotation><xs:documentation>A picture. Repeatable; screens use the first.</xs:documentation></xs:annotation>
          </xs:element>
          <xs:element name="video" type="k:video">
            <xs:annotation><xs:documentation>A video. One per item.</xs:documentation></xs:annotation>
          </xs:element>
          <xs:element name="link" type="k:link">
            <xs:annotation><xs:documentation>The item's web page. Carried to screens; no current template displays it.</xs:documentation></xs:annotation>
          </xs:element>
          <xs:element name="tags" type="k:tags">
            <xs:annotation><xs:documentation>Free words a template can select on.</xs:documentation></xs:annotation>
          </xs:element>
          <xs:any namespace="##other" processContents="lax"/>
        </xs:choice>
      </xs:sequence>
      <xs:attribute name="id" type="k:token" use="required">
        <xs:annotation><xs:documentation>Required. Unique in the feed, and stable from one fetch to the next: playlists refer to items by it, and a second item with the same id is dropped.</xs:documentation></xs:annotation>
      </xs:attribute>
      <xs:attribute name="kind" type="k:token" use="required">
        <xs:annotation><xs:documentation>Required. event, news, media, program, ad or notice. Screens keep other kinds, and templates that do not ask for them never show them.</xs:documentation></xs:annotation>
      </xs:attribute>
      <xs:attribute name="from" type="xs:dateTime">
        <xs:annotation><xs:documentation>Not shown before this moment, so you can publish ahead.</xs:documentation></xs:annotation>
      </xs:attribute>
      <xs:attribute name="until" type="xs:dateTime">
        <xs:annotation><xs:documentation>Not shown after this moment.</xs:documentation></xs:annotation>
      </xs:attribute>
      <xs:attribute name="priority" type="k:priority">
        <xs:annotation><xs:documentation>1 (first) to 9 (last), default 5. Used where a template orders by priority.</xs:documentation></xs:annotation>
      </xs:attribute>
      <xs:attribute name="dwell" type="xs:positiveInteger">
        <xs:annotation><xs:documentation>Seconds a picture stays on the stage, instead of the template's setting.</xs:documentation></xs:annotation>
      </xs:attribute>
      <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:complexType>
  </xs:element>

  <xs:element name="playlist">
    <xs:annotation><xs:documentation>A named, ordered list of items you curate — "what we want on the big screen". A template can show a playlist instead of choosing by kind.</xs:documentation></xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="ref" minOccurs="0" maxOccurs="unbounded">
          <xs:annotation><xs:documentation>One item in the playlist, by its id. A ref to an item that is not in the feed is dropped.</xs:documentation></xs:annotation>
          <xs:complexType>
            <xs:attribute name="item" type="k:token" use="required"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="name" type="k:token" use="required"/>
    </xs:complexType>
  </xs:element>

  <!-- types -->

  <xs:simpleType name="token">
    <xs:restriction base="xs:string"><xs:minLength value="1"/><xs:pattern value="\S+"/></xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="text120">
    <xs:restriction base="xs:string"><xs:minLength value="1"/></xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="priority">
    <xs:restriction base="xs:integer"><xs:minInclusive value="1"/><xs:maxInclusive value="9"/></xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="webURL">
    <xs:restriction base="xs:anyURI"><xs:pattern value="https?://.+"/></xs:restriction>
  </xs:simpleType>

  <xs:complexType name="body">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="format" default="text">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:enumeration value="text"/>
              <xs:enumeration value="markdown"/>
            </xs:restriction>
          </xs:simpleType>
        </xs:attribute>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:complexType name="image">
    <xs:attribute name="src" type="k:webURL" use="required">
      <xs:annotation><xs:documentation>An absolute http(s) address of a JPEG, PNG or WebP, up to 4096 px on the long edge. Screens scale it down themselves, so an original is fine.</xs:documentation></xs:annotation>
    </xs:attribute>
    <xs:attribute name="width" type="xs:positiveInteger"/>
    <xs:attribute name="height" type="xs:positiveInteger"/>
    <xs:attribute name="alt" type="xs:string"/>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:complexType name="video">
    <xs:attribute name="src" type="k:webURL" use="required">
      <xs:annotation><xs:documentation>An absolute http(s) address of an MP4: H.264 (level 4.1 or lower) or HEVC, at most 1080p30 and 200 MB, with the index at the front (+faststart).</xs:documentation></xs:annotation>
    </xs:attribute>
    <xs:attribute name="width" type="xs:positiveInteger"/>
    <xs:attribute name="height" type="xs:positiveInteger"/>
    <xs:attribute name="duration" type="xs:positiveInteger">
      <xs:annotation><xs:documentation>Seconds; how long the stage gives the video.</xs:documentation></xs:annotation>
    </xs:attribute>
    <xs:attribute name="poster" type="k:webURL">
      <xs:annotation><xs:documentation>A picture to show while the video loads.</xs:documentation></xs:annotation>
    </xs:attribute>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
  </xs:complexType>

  <xs:complexType name="link">
    <xs:attribute name="href" type="k:webURL" use="required"/>
  </xs:complexType>

  <xs:complexType name="tags">
    <xs:sequence>
      <xs:element name="tag" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
