<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (C) 2000 - 2024 Silverpeas

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    As a special exception to the terms and conditions of version 3.0 of
    the GPL, you may redistribute this Program in connection with Free/Libre
    Open Source Software ("FLOSS") applications as described in Silverpeas's
    FLOSS exception.  You should have received a copy of the text describing
    the FLOSS exception, and it is also available here:
    "https://www.silverpeas.org/legal/floss_exception.html"

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

-->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
	<!-- .......................................... DEFINITION DE MODÈLE DE PROCEDURE -->
	<xs:element name="processModel">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="label" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element ref="description" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element ref="roles"/>
				<xs:element ref="presentation" minOccurs="0"/>
				<xs:element ref="participants" minOccurs="0"/>
				<xs:element ref="states"/>
				<xs:element ref="actions" minOccurs="0"/>
				<xs:element ref="userInfos" minOccurs="0" />
				<xs:element ref="dataFolder"/>
				<xs:element ref="forms" minOccurs="0"/>
			</xs:sequence>
			<xs:attribute name="name" type="xs:string" use="required"/>
		</xs:complexType>
	</xs:element>
	<!-- ................................................................. DEFINITION D'UN ROLE -->
	<xs:element name="role">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="label" maxOccurs="unbounded"/>
				<xs:element ref="description" minOccurs="0" maxOccurs="unbounded"/>
			</xs:sequence>
			<xs:attribute name="name" type="xs:ID" use="required"/>
		</xs:complexType>
	</xs:element>
	<!-- ................................................................. DEFINITION D'UN PARTICIPANT -->
	<xs:element name="participant">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="label" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element ref="description" minOccurs="0" maxOccurs="unbounded"/>
			</xs:sequence>
			<xs:attribute name="name" type="xs:ID" use="required"/>
			<xs:attribute name="resolvedState" type="xs:IDREF"/>
		</xs:complexType>
	</xs:element>
	<!-- ................................................................. DEFINITION D'UNE ACTION -->
	<xs:element name="action">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="label" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element ref="description" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element ref="allowedUsers" minOccurs="0"/>
				<xs:element ref="consequences" minOccurs="0"/>
			</xs:sequence>
			<xs:attribute name="name" type="xs:ID" use="required"/>
			<xs:attribute name="form" type="xs:string" use="optional"/> <!-- can't use IDREF, no ID in form -->
			<xs:attribute name="kind" type="xs:string" default="update"/>
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION D'UN LABEL -->
	<xs:element name="label">
		<xs:complexType>
			<xs:simpleContent>
				<xs:extension base="xs:string">
					<xs:attribute name="lang" type="xs:string" default="default"/>
					<xs:attribute name="role" type="xs:string" default="default"/>
				</xs:extension>
			</xs:simpleContent>
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION D'UNE ACTIVITE-->
	<xs:element name="activity">
		<xs:complexType>
			<xs:simpleContent>
				<xs:extension base="xs:string">
					<xs:attribute name="lang" type="xs:string" default="default"/>
					<xs:attribute name="role" type="xs:string" default="default"/>
				</xs:extension>
			</xs:simpleContent>
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION D'UNE DESCRIPTION-->
	<xs:element name="description">
		<xs:complexType>
			<xs:simpleContent>
				<xs:extension base="xs:string">
					<xs:attribute name="lang" type="xs:string" default="default"/>
					<xs:attribute name="role" type="xs:string" default="default"/>
				</xs:extension>
			</xs:simpleContent>
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION D'UN TITRE-->
	<xs:element name="title">
		<xs:complexType>
			<xs:simpleContent>
				<xs:extension base="xs:string">
					<xs:attribute name="lang" type="xs:string" default="default"/>
					<xs:attribute name="role" type="xs:string" default="default"/>
				</xs:extension>
			</xs:simpleContent>
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION D'UN ETAT -->
	<xs:element name="state">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="label" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element ref="activity" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element ref="description" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element ref="workingUsers" minOccurs="0"/>
				<xs:element ref="interestedUsers" minOccurs="0"/>
				<xs:element ref="allowedActions" minOccurs="0"/>
				<xs:element ref="preconditions" minOccurs="0"/>
        <xs:element ref="timeOutActions" minOccurs="0"/>
			</xs:sequence>
			<xs:attribute name="name" type="xs:ID" use="required"/>
			<xs:attribute name="timeoutInterval" type="xs:integer"/>
			<xs:attribute name="timeoutNotifyAdmin" type="xs:boolean" default="false"/>
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION D'UN FORMULAIRE -->
	<xs:element name="form">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="title" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element name="input" minOccurs="0" maxOccurs="unbounded">
					<xs:complexType>
						<xs:sequence>
							<xs:element ref="label" minOccurs="0"/>
						</xs:sequence>
						<xs:attribute name="item" type="xs:IDREF"/>
						<xs:attribute name="value" type="xs:string"/>
						<xs:attribute name="readonly" type="xs:boolean" default="false"/>
						<xs:attribute name="displayerName" type="xs:string"/>
						<xs:attribute name="mandatory" type="xs:boolean" default="false"/>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
			<xs:attribute name="name" type="xs:string" use="required"/> <!-- name is not an id (not solenly) -->
            <xs:attribute name="role" type="xs:IDREFS"/>
			<xs:attribute name="HTMLFileName" type="xs:string"/>
		</xs:complexType>
	</xs:element>
	<!-- ........................................................... DEFINITION DES DONNEES UTILISATEUR -->
	<xs:element name="userInfos">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="item" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION D'UN DOSSIER -->
	<xs:element name="dataFolder">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="item" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION D'UN ITEM -->
	<xs:element name="formula" type="xs:string"/>
	<xs:element name="readonly" type="xs:boolean"/>
	<xs:element name="type" type="xs:string"/>
	<xs:element name="item">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="label" minOccurs="0"/>
				<xs:element ref="description" minOccurs="0"/>
				<xs:element ref="type" minOccurs="0"/>
				<xs:element ref="readonly" minOccurs="0"/>
        <xs:element ref="param" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element ref="formula" minOccurs="0"/>
			</xs:sequence>
			<xs:attribute name="name" type="xs:ID" use="required"/>
			<xs:attribute name="computed" type="xs:boolean" default="false"/>
			<xs:attribute name="mapTo" type="xs:IDREF"/>
		</xs:complexType>
	</xs:element>
    <!-- ...................................................................... DEFINITION D'UN PARAMETRE -->
    <xs:element name="param">
        <xs:complexType>
            <xs:attribute name="name" type="xs:string" use="required"/>
            <xs:attribute name="value" type="xs:string" use="required"/>
        </xs:complexType>
    </xs:element>
	<!-- ...................................................................... DEFINITION DES IMPACTS -->
	<xs:element name="consequences">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="consequence" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>

	<xs:element name="kill" type="xs:boolean"/>

	<xs:element name="consequence">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="kill" minOccurs="0"/>
				<xs:choice maxOccurs="unbounded">
					<xs:element name="set">
						<xs:complexType>
							<xs:attribute name="state" type="xs:IDREF" use="required"/>
						</xs:complexType>
					</xs:element>
					<xs:element name="unset">
						<xs:complexType>
							<xs:attribute name="state" type="xs:IDREF" use="required"/>
						</xs:complexType>
					</xs:element>
					<xs:element ref="notifiedUsers" minOccurs="0"/>
				</xs:choice>
        <xs:element ref="notify" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element ref="triggers" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="item" type="xs:IDREF" />
      <xs:attribute name="operator" type="xs:string"/>
      <xs:attribute name="value" type="xs:string"/>
		</xs:complexType>
	</xs:element>

  <xs:element name="triggers">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="trigger" minOccurs="1" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="trigger">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="param" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="name" type="xs:string" />
      <xs:attribute name="handler" type="xs:string" />
    </xs:complexType>
  </xs:element>

  <xs:element name="notify">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="relatedUser" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element ref="userInRole" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="message" type="xs:string" />
    </xs:complexType>
  </xs:element>

	<!-- ...................................................................... DEFINITION DES UTILISATEURS CALCULES -->
	<xs:element name="relatedUser">
		<xs:complexType>
			<xs:attribute name="participant" type="xs:IDREF" use="optional"/>
			<xs:attribute name="folderItem" type="xs:IDREF" use="optional"/>
			<xs:attribute name="relation" type="xs:IDREF" use="optional"/>
			<xs:attribute name="role" type="xs:IDREF" use="required"/>
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION DES UTILISATEURS NOTIFIES -->
	<xs:element name="notifiedUsers">
		<xs:complexType>
            <xs:sequence>
			    <xs:element ref="relatedUser" maxOccurs="unbounded"/>
            </xs:sequence>
			<xs:attribute name="message" type="xs:string"/>
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION DES UTILISATEURS AFFECTES -->
	<xs:element name="workingUsers">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="relatedUser" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element ref="userInRole" minOccurs="0" maxOccurs="unbounded"/> <!-- plusieurs possible -->
			</xs:sequence>
			<xs:attribute name="role" type="xs:string" />
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION DES UTILISATEURS IMPACTES -->
	<xs:element name="interestedUsers">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="relatedUser" minOccurs="0" maxOccurs="unbounded"/>
				<xs:element ref="userInRole" minOccurs="0" maxOccurs="unbounded"/>
			</xs:sequence>
			<xs:attribute name="role" type="xs:string"/>
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION D'UNE PRESENTATION -->
	<xs:element name="presentation">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="title" maxOccurs="unbounded"/>
				<xs:element ref="columns" minOccurs="0" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<!-- ...................................................................... DEFINITION DES PRE-REQUIS A UNE ACTION -->
	<xs:element name="preconditions">
		<xs:complexType/>
	</xs:element>
	<!-- ...................................... DEFINITION D'UNE LISTE DE PERSONNES AYANT UN ROLE DONNE  -->
	<xs:element name="userInRole">
		<xs:complexType>
			<xs:attribute name="name" type="xs:IDREF" use="required"/>
		</xs:complexType>
	</xs:element>
	<!-- .................................................... DEFINITION D'UNE LISTE D'ETATS -->
	<xs:element name="states">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="state" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<!-- .................................................... DEFINITION D'UNE LISTE DE PARTICIPANTS -->
	<xs:element name="participants">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="participant" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<!-- .................................................... DEFINITION D'UNE LISTE DE COLONNES -->
	<xs:element name="columns">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="column" minOccurs="0" maxOccurs="unbounded">
					<xs:complexType>
						<xs:attribute name="item" type="xs:IDREF" use="required"/>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
			<xs:attribute name="role" type="xs:string" use="optional"/>
		</xs:complexType>
	</xs:element>
	<!-- .................................................... DEFINITION D'UNE LISTE DE FORMULAIRES -->
	<xs:element name="forms">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="form" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<!-- .................................................... DEFINITION D'UNE LISTE D'ACTIONS AUTORISEES -->
	<xs:element name="roles">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="role" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<!-- .................................................... DEFINITION D'UNE LISTE D'ACTIONS -->
	<xs:element name="actions">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="action" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<!-- .................................................... DEFINITION D'UNE LISTE D'ACTIONS AUTORISEES -->
	<xs:element name="allowedActions">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="allow" minOccurs="0" maxOccurs="unbounded">
					<xs:complexType>
						<xs:attribute name="action" type="xs:IDREF" use="required"/>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
  <!-- .................................................... DEFINITION D'UNE LISTE D'ACTIONS RETARDEES -->
  <xs:element name="timeOutActions">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="timeOutAction" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <xs:attribute name="action" type="xs:IDREF" use="required"/>
            <xs:attribute name="delay" type="xs:string" use="required"/>
            <xs:attribute name="order" type="xs:string" use="required"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <!-- .................................................... DEFINITION D'UNE LISTE DUTILISATEURS AUTORISES -->
	<xs:element name="allowedUsers">
		<xs:complexType>
			<xs:sequence>
                <xs:element ref="relatedUser" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="userInRole" minOccurs="0" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>
