<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2008-2016 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/permissions.xsd"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns="http://schemas.haulmont.com/cuba/permissions.xsd"
        elementFormDefault="qualified"
        attributeFormDefault="unqualified">

    <xs:element name="permission-config" type="permissionConfigType"/>

    <xs:complexType name="permissionConfigType">
        <xs:sequence>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="include" type="includeType"/>
            </xs:choice>
            <xs:choice minOccurs="0" maxOccurs="1">
                <xs:element name="specific" type="categoryOrPermission" minOccurs="1" maxOccurs="1"/>
            </xs:choice>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="categoryOrPermission">
        <xs:sequence>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="category" type="categoryType"/>
                <xs:element name="permission" type="permissionType"/>
            </xs:choice>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="categoryType">
        <xs:complexContent>
            <xs:extension base="categoryOrPermission">
                <xs:attribute name="id" type="xs:string"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="permissionType">
        <xs:attribute name="id" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="includeType">
        <xs:attribute name="file" type="xs:string"/>
    </xs:complexType>
</xs:schema>