<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:fews="http://www.wldelft.nl/fews"
           targetNamespace="http://www.wldelft.nl/fews"
           elementFormDefault="qualified">

  <!-- Reusable simple types -->

  <xs:simpleType name="yesNoType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="yes"/>
      <xs:enumeration value="no"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="dbServerType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="postgres"/>
      <xs:enumeration value="oracle"/>
      <xs:enumeration value="sqlserver"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="portType">
    <xs:restriction base="xs:positiveInteger">
      <xs:minInclusive value="1"/>
      <xs:maxInclusive value="65535"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="dbIntIdType">
    <xs:annotation>
      <xs:documentation>Unique offset in the synchronisation pool (0–97) for generating globalRowIds.</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="0"/>
      <xs:maxInclusive value="97"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- Root element -->

  <xs:element name="SETTINGS">
    <xs:complexType>
      <xs:all>
        <xs:element name="COMMON"   type="fews:commonType"/>
        <xs:element name="LOCALMC"  type="fews:localMcType"/>
        <xs:element name="OC"       type="fews:ocType"      minOccurs="0"/>
        <xs:element name="WEBOC"    type="fews:webOcType"   minOccurs="0"/>
        <xs:element name="FSS"      type="fews:fssType"     minOccurs="0"/>
        <xs:element name="AI"       type="fews:aiType"      minOccurs="0"/>
        <xs:element name="PI"       type="fews:piType"      minOccurs="0"/>
        <xs:element name="WS"       type="fews:wsType"      minOccurs="0"/>
        <xs:element name="ARCHIVE"  type="fews:archiveType" minOccurs="0"/>
        <xs:element name="DBPROXY"  type="fews:dbProxyType" minOccurs="0"/>
      </xs:all>
    </xs:complexType>
  </xs:element>

  <!-- COMMON -->

  <xs:complexType name="commonType">
    <xs:all>
      <xs:element name="InstallDir" type="xs:string">
        <xs:annotation><xs:documentation>Directory in which components will be installed.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="MCRegionName" type="xs:string">
        <xs:annotation><xs:documentation>Name for the live system, used to label OC/CM shortcuts.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="OSUsername" type="xs:string">
        <xs:annotation><xs:documentation>Windows service user for FEWS.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="OSUserDomain" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Optional domain for the FEWS user. Omit for a local account.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="OSUserPass" type="xs:string">
        <xs:annotation><xs:documentation>Password for the Windows FEWS user.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="ADAuthenticationYesNo" type="fews:yesNoType">
        <xs:annotation><xs:documentation>Enable Active Directory authentication.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="ReplaceEnvYesNo" type="fews:yesNoType">
        <xs:annotation><xs:documentation>Replace existing environment variables if they already exist.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="ForceYesNo" type="fews:yesNoType">
        <xs:annotation><xs:documentation>Install even if the current version is already up-to-date.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="NoBackupsYesNo" type="fews:yesNoType">
        <xs:annotation><xs:documentation>If yes, do not make backups of previous web component versions.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="RestartServices" type="fews:yesNoType">
        <xs:annotation><xs:documentation>Restart services automatically after an upgrade.</xs:documentation></xs:annotation>
      </xs:element>
    </xs:all>
  </xs:complexType>

  <!-- LOCALMC -->

  <xs:complexType name="localMcType">
    <xs:all>
      <xs:element name="MCID" type="xs:string">
        <xs:annotation><xs:documentation>Unique MC identifier, always ending with MC0n (e.g. TestMC00).</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="DB" type="fews:dbType"/>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="dbType">
    <xs:all>
      <xs:element name="DBServerType" type="fews:dbServerType">
        <xs:annotation><xs:documentation>Database flavour: postgres, oracle, or sqlserver.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="HostName" type="xs:string">
        <xs:annotation><xs:documentation>Database server IP address or host name.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="DBServerPort" type="fews:portType">
        <xs:annotation><xs:documentation>Database server port (e.g. 1433 for SQL Server, 5432 for PostgreSQL, 1521 for Oracle).</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="DBInstance" type="xs:string">
        <xs:annotation><xs:documentation>Name of the database.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="DBIntId" type="fews:dbIntIdType">
        <xs:annotation><xs:documentation>Unique offset (0–97) in the synchronisation pool for generating globalRowIds. Used when creating the database from scratch.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="DBSchemaName" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Optional schema name. Must be "dbo" for release 2018.02. Defaults to the DB user name. SQL Server only.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="DBUser" type="xs:string">
        <xs:annotation><xs:documentation>FEWS database user.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="DBPass" type="xs:string">
        <xs:annotation><xs:documentation>Password for the FEWS database user (plain text).</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="DBEncryptedPass" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Encrypted password for the FEWS database user. Takes precedence over DBPass when set.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="SAUser" type="xs:string">
        <xs:annotation><xs:documentation>Database system administrator user.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="SAPass" type="xs:string">
        <xs:annotation><xs:documentation>Password for the database system administrator user.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="DataDir" type="xs:string">
        <xs:annotation><xs:documentation>Path where the database stores data files.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="IndexDir" type="xs:string">
        <xs:annotation><xs:documentation>Path where the database stores index files.</xs:documentation></xs:annotation>
      </xs:element>
    </xs:all>
  </xs:complexType>

  <!-- OC (Operator Client / Config Manager) -->

  <xs:complexType name="ocType">
    <xs:all>
      <xs:element name="UserRegionHome" type="xs:string">
        <xs:annotation><xs:documentation>Directory where OC and CM shortcuts will be created.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="ClientConfig" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Optional custom OC client config file name. Defaults to oc_clientConfig.xml.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="RegionHomeInLocalAppdata" type="fews:yesNoType" minOccurs="0">
        <xs:annotation><xs:documentation>Create the client Region Home in %LOCALAPPDATA%. Defaults to yes.</xs:documentation></xs:annotation>
      </xs:element>
    </xs:all>
  </xs:complexType>

  <!-- WEBOC (Web Operator Client) -->

  <xs:complexType name="webOcType">
    <xs:all>
      <xs:element name="HTTPPort" type="fews:portType">
        <xs:annotation><xs:documentation>IIS HTTP port for Web OC.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="PhysicalPath" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Where to create the IIS site on the file system. Defaults to &lt;InstallDir&gt;\IIS.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="WebServicesUrl" type="xs:anyURI">
        <xs:annotation><xs:documentation>URL of the Web Services to connect to (must be reachable from the Web OC host).</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="ProxyRewriteSlug" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Trailing URL segment to be reverse-proxied. Requires ProxyRewriteUrl.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="ProxyRewriteUrl" type="xs:anyURI" minOccurs="0">
        <xs:annotation><xs:documentation>Internal URL that the reverse proxy forwards requests to.</xs:documentation></xs:annotation>
      </xs:element>
    </xs:all>
  </xs:complexType>

  <!-- FSS (Forecasting Shell Script) -->

  <xs:complexType name="fssType">
    <xs:all>
      <xs:element name="NumberOfFSS" type="xs:positiveInteger">
        <xs:annotation><xs:documentation>Total number of FSS instances to install for this MC.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="ClientConfig" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Optional custom FSS client config file name. Defaults to fss_clientConfig.xml.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="FSSgroup" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>FSS group name. Defaults to "windows".</xs:documentation></xs:annotation>
      </xs:element>
    </xs:all>
  </xs:complexType>

  <!-- AI (Admin Interface – Tomcat) -->

  <xs:complexType name="aiType">
    <xs:all>
      <xs:element name="HTTPPort" type="fews:portType">
        <xs:annotation><xs:documentation>Tomcat HTTP connector port for the Admin Interface.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="JvmMs" type="xs:positiveInteger">
        <xs:annotation><xs:documentation>Minimum JVM heap size for Tomcat (MB).</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="JvmMx" type="xs:positiveInteger">
        <xs:annotation><xs:documentation>Maximum JVM heap size for Tomcat (MB).</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="AIAdminUser" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>AI admin user name. Defaults to the MCID value.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="AIAdminKey" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Existing AI access key for the AI admin user. Wrap in CDATA.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="TomcatAuthenticationYesNo" type="fews:yesNoType">
        <xs:annotation><xs:documentation>Enable Tomcat authentication.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="AIAdminGroups" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Optional LDAP groups mapped to the AI_ADMIN role.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="AIViewerGroups" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Optional LDAP groups mapped to the AI_VIEWER role.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="AIUserManagerGroups" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Optional LDAP groups mapped to the AI_USER_MANAGER role.</xs:documentation></xs:annotation>
      </xs:element>
    </xs:all>
  </xs:complexType>

  <!-- PI (Web Services – Tomcat) -->

  <xs:complexType name="piType">
    <xs:all>
      <xs:element name="HTTPPort" type="fews:portType">
        <xs:annotation><xs:documentation>Tomcat HTTP connector port for Web Services.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="JvmMs" type="xs:positiveInteger">
        <xs:annotation><xs:documentation>Minimum JVM heap size for Tomcat (MB).</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="JvmMx" type="xs:positiveInteger">
        <xs:annotation><xs:documentation>Maximum JVM heap size for Tomcat (MB).</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="PiClientConfig" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Optional custom Web Services client config file name. Defaults to ws_clientConfig.xml.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="WebServicesUrl" type="xs:anyURI">
        <xs:annotation><xs:documentation>Web Services URL, used by Web OC.</xs:documentation></xs:annotation>
      </xs:element>
    </xs:all>
  </xs:complexType>

  <!-- WS (Web Services – Launcher) -->

  <xs:complexType name="wsType">
    <xs:all>
      <xs:element name="WSPort" type="fews:portType">
        <xs:annotation><xs:documentation>HTTP port for the Web Services Launcher.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="WsClientConfig" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Optional custom WS client config file name. Defaults to ws_clientConfig.xml.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="WSID" type="xs:string" minOccurs="0">
        <xs:annotation><xs:documentation>Optional WS identifier used to name the WS Region Home folder. Defaults to "WS00".</xs:documentation></xs:annotation>
      </xs:element>
    </xs:all>
  </xs:complexType>

  <!-- ARCHIVE -->

  <xs:complexType name="archiveType">
    <xs:all>
      <xs:element name="RootDir" type="xs:string">
        <xs:annotation><xs:documentation>Root directory for the archive.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="HTTPPort" type="fews:portType">
        <xs:annotation><xs:documentation>Tomcat HTTP connector port for the Archive service.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="JvmMs" type="xs:positiveInteger">
        <xs:annotation><xs:documentation>Minimum JVM heap size for Tomcat (MB).</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="JvmMx" type="xs:positiveInteger">
        <xs:annotation><xs:documentation>Maximum JVM heap size for Tomcat (MB).</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="User" type="xs:string">
        <xs:annotation><xs:documentation>Archive service user name.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="Password" type="xs:string">
        <xs:annotation><xs:documentation>Archive service user password.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="ArchiveName" type="xs:string">
        <xs:annotation><xs:documentation>Display name for the archive.</xs:documentation></xs:annotation>
      </xs:element>
    </xs:all>
  </xs:complexType>

  <!-- DBPROXY (Database Proxy) -->

  <xs:complexType name="dbProxyType">
    <xs:all>
      <xs:element name="HTTPPort" type="fews:portType">
        <xs:annotation><xs:documentation>Tomcat HTTP connector port for the Database Proxy.</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="JvmMs" type="xs:positiveInteger">
        <xs:annotation><xs:documentation>Minimum JVM heap size for Tomcat (MB).</xs:documentation></xs:annotation>
      </xs:element>
      <xs:element name="JvmMx" type="xs:positiveInteger">
        <xs:annotation><xs:documentation>Maximum JVM heap size for Tomcat (MB).</xs:documentation></xs:annotation>
      </xs:element>
    </xs:all>
  </xs:complexType>

</xs:schema>
