<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2008-2017 Haulmont.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<xs:schema targetNamespace="http://schemas.haulmont.com/cuba/rest-json-transformations.xsd"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="http://schemas.haulmont.com/cuba/rest-json-transformations.xsd"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified">

    <xs:element name="transformations" type="transformationsType"/>

    <xs:complexType name="transformationsType">
        <xs:sequence>
            <xs:element name="transformation" type="transformationType" maxOccurs="unbounded" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="transformationType">
        <xs:sequence>
            <xs:element name="custom" type="customType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="renameAttribute" type="renamedAttributeType" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="fromVersion" type="oneDirectionTransformation" minOccurs="0" maxOccurs="1"/>
            <xs:element name="toVersion" type="oneDirectionTransformation" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="modelVersion" type="xs:string" use="required"/>
        <xs:attribute name="currentEntityName" type="xs:string" use="required"/>
        <xs:attribute name="oldEntityName" type="xs:string" use="optional"/>
    </xs:complexType>

    <xs:complexType name="renamedAttributeType">
        <xs:attribute name="oldName" type="xs:string" use="required"/>
        <xs:attribute name="currentName" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="oneDirectionTransformation">
        <xs:sequence>
            <xs:element name="removeAttribute" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:attribute name="name" type="xs:string" use="required"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="customType">
        <xs:sequence>
            <xs:element name="fromVersion" minOccurs="0" maxOccurs="1">
                <xs:complexType>
                    <xs:attribute name="transformerBeanRef" type="xs:string" use="required"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="toVersion" minOccurs="0" maxOccurs="1">
                <xs:complexType>
                    <xs:attribute name="transformerBeanRef" type="xs:string" use="required"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>