<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:include schemaLocation="netvisorgeneraltypes.xsd" />

    <!-- Rules XSD cannot express are validated in code (ExternalPaymentBatchValidator):
         paymentdate belongs to Salary and duedate to Transfer, a transfer row carries either a reference or a message, hetu is required for Salary, the
         account must be a Finnish IBAN matching the given bic, the batch has at most 5000 rows,
         and the sum / hetu / reference formats. -->

    <xs:simpleType name="payrollexternalpaymentbatch_paymenttype">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Salary" />
            <xs:enumeration value="Transfer" />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="payrollexternalpaymentbatch_message">
        <xs:restriction base="xs:string">
            <xs:maxLength value="140" />
        </xs:restriction>
    </xs:simpleType>

    <xs:element name="root">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="payrollexternalpaymentbatch">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="batchdescription" type="netvisor_string_min1_max250" minOccurs="1" maxOccurs="1" />
                            <xs:element name="paymenttype" type="payrollexternalpaymentbatch_paymenttype" minOccurs="1" maxOccurs="1" />
                            <xs:choice minOccurs="1" maxOccurs="1">
                                <xs:element name="paymentdate" type="netvisor_date" />
                                <xs:element name="duedate" type="netvisor_date" />
                            </xs:choice>
                            <xs:element name="payrollexternalpaymentbatchrow" minOccurs="1" maxOccurs="unbounded">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="externalpaymentsum" type="netvisor_decimal_string" minOccurs="1" maxOccurs="1" />
                                        <xs:element name="iban" type="netvisor_string_min1_max50" minOccurs="1" maxOccurs="1" />
                                        <xs:element name="bic" type="netvisor_string_max12" minOccurs="1" maxOccurs="1" />
                                        <xs:element name="realname" type="netvisor_string_max70" minOccurs="1" maxOccurs="1" />
                                        <xs:element name="hetu" type="netvisor_string_max12" minOccurs="0" maxOccurs="1" />
                                        <xs:element name="reference" type="netvisor_string_max30" minOccurs="0" maxOccurs="1" />
                                        <xs:element name="message" type="payrollexternalpaymentbatch_message" minOccurs="0" maxOccurs="1" />
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
