<?xml version="1.0"?>
<!--

    Copyright Onix Solutions Limited [OnixS]. All rights reserved.

    This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
    and international copyright treaties.

    Access to and use of the software is governed by the terms of the applicable OnixS Software
    Services Agreement (the Agreement) and Customer end user license agreements granting
    a non-assignable, non-transferable and non-exclusive license to use the software
    for it's own data processing purposes under the terms defined in the Agreement.

    Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
    of this source code or associated reference material to any other location for further reproduction
    or redistribution, and any amendments to this copyright notice, are expressly prohibited.

    Any reproduction or redistribution for sale or hiring of the Software not in accordance with
    the terms of the Agreement is a violation of copyright law.
    
-->

<xs:schema
        targetNamespace="http://ref.onixs.biz/fix/scheduler"
        xmlns="http://ref.onixs.biz/fix/scheduler"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        attributeFormDefault="unqualified"
        elementFormDefault="qualified"
        version="1.8">

    <xs:element name="SchedulerSettings" type="SchedulerSettings"/>

    <xs:complexType name="SchedulerSettings">
        <xs:sequence>
            <xs:element name="Schedules" type="Schedules" minOccurs="0" maxOccurs="1"/>
            <xs:element name="Connections" type="Connections" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="threadingModel" type="SchedulerThreadingModel" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Specifies the way in which the Scheduler utilizes threads.
                    When present, the value takes precedence over the one set in the Scheduler options.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="serviceThreadAffinity" type="CpuIndexes" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Specifies the CPU index(es) for affinity of the Scheduler service thread.
                    Symbol ',' is used as the cpu index delimiter.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="reconnectAttempts" type="xs:nonNegativeInteger" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Specifies the number of logon attempts in case of a logon failure.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="reconnectInterval" type="xs:positiveInteger" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Specifies the time interval between logon attempts in case of a logon failure (in seconds).
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="utcTimeUsage" type="xs:boolean" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Specifies whether the Scheduler uses the UTC time instead of the local time.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="Schedules">
        <xs:sequence>
            <xs:element name="Schedule" type="Schedule" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="Schedule">
        <xs:attribute name="id" type="xs:string"/>
        <xs:attribute name="firstDay" type="DayOfWeek"/>
        <xs:attribute name="lastDay" type="DayOfWeek"/>
        <xs:attribute name="logonTime" type="LTime"/>
		<xs:attribute name="logonTimeZone" type="xs:string"/>
        <xs:attribute name="logoutTime" type="LTime"/>
		<xs:attribute name="logoutTimeZone" type="xs:string"/>
        <xs:attribute name="sessionDuration" type="SessionDuration"/>
        <xs:attribute name="resetSessionNumber" type="ResetSessionNumber"/>
    </xs:complexType>

    <xs:complexType name="Connections">
        <xs:sequence>
            <xs:element name="Connection" type="Connection" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="Connection">
        <xs:sequence>
            <xs:element name="Counterparty" type="Counterparty" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="id" type="xs:string"/>
        <xs:attribute name="role" type="ConnectionRole"/>
        <xs:attribute name="host" type="xs:string" use="optional"/>
        <xs:attribute name="port" type="xs:int" use="optional"/>
        <xs:attribute name="setResetSeqNumbers" type="xs:boolean" use="optional"/>
        <xs:attribute name="heartbeatInterval" type="xs:int" use="optional"/>
        <xs:attribute name="customLogonMessageFile" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation xml:lang="en">
                    Specifies the FIX logon message file/resource to use. The field delimiter '0x01' is expected.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="customLogonMessage" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Specifies the inline FIX logon message to use. The field delimiter can be specified in
                    the 'customLogonMessageFieldDelimiter' attribute.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="customLogonMessageFieldDelimiter" type="xs:string" use="optional" default="|">
            <xs:annotation>
                <xs:documentation>
                    Specifies the field delimiter used in the 'customLogonMessage' attribute.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="Counterparty">
        <xs:attribute name="host" type="xs:string" use="required"/>
        <xs:attribute name="port" type="xs:int" use="required"/>
    </xs:complexType>

    <xs:simpleType name="DayOfWeek">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Sunday"/>
            <xs:enumeration value="Monday"/>
            <xs:enumeration value="Tuesday"/>
            <xs:enumeration value="Wednesday"/>
            <xs:enumeration value="Thursday"/>
            <xs:enumeration value="Friday"/>
            <xs:enumeration value="Saturday"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="SessionDuration">
        <xs:restriction base="xs:string">
            <xs:enumeration value="day"/>
            <xs:enumeration value="week"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="ResetSessionNumber">
        <xs:restriction base="xs:string">
            <xs:enumeration value="never"/>
            <xs:enumeration value="daily"/>
            <xs:enumeration value="weekly"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="ConnectionRole">
        <xs:restriction base="xs:string">
            <xs:enumeration value="initiator"/>
            <xs:enumeration value="acceptor"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="LTime">
        <xs:restriction base="xs:string">
            <xs:pattern value="\d{1,2}:\d{2}(:\d{2})?"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="SchedulerThreadingModel">
        <xs:restriction base="xs:string">
            <xs:enumeration value="DedicatedThreads"/>
            <xs:enumeration value="ExternalThread"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="CpuIndexes">
        <xs:restriction base="xs:string">
            <xs:pattern value="\d+(,\d+)*"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>
