<?xml version="1.0" encoding="utf-8"?>
<!--
 Copyright 2021 Google LLC

 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

     https://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 attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="queue-entries" type="queue-entries-Type"/>

  <xs:complexType name="queue-entries-Type">
    <xs:sequence>
      <xs:element type="total-storage-limit-Type" name="total-storage-limit" maxOccurs="1" minOccurs="0"/>
      <xs:element type="queue-Type" name="queue" maxOccurs="unbounded" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:simpleType name="total-storage-limit-Type">
    <xs:restriction base="xs:string">
      <xs:pattern value="([0-9]+(\.[0-9]*)?[BKMGT]?)"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="queue-Type">
    <xs:all>
      <xs:element type="name-Type" name="name"/>
      <xs:element type="rate-Type" name="rate" minOccurs="0"/>
      <xs:element type="xs:nonNegativeInteger" name="bucket-size" minOccurs="0"/>
      <xs:element type="xs:nonNegativeInteger" name="max-concurrent-requests" minOccurs="0"/>
      <xs:element type="retry-parameters-Type" name="retry-parameters" minOccurs="0"/>
      <xs:element type="target-Type" name="target" minOccurs="0"/>
      <xs:element type="queue-mode-Type" name="mode" minOccurs="0"/>
      <xs:element type="acl-Type" name="acl" minOccurs="0"/>
    </xs:all>
  </xs:complexType>

  <xs:simpleType name="queue-mode-Type">
    <xs:restriction base="xs:string">
      <xs:pattern value="push|pull"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="acl-Type">
    <xs:choice maxOccurs="unbounded">
      <xs:element type="xs:string" name="user-email" maxOccurs="unbounded" minOccurs="0"/>
      <xs:element type="xs:string" name="writer-email" maxOccurs="unbounded" minOccurs="0"/>
    </xs:choice>
  </xs:complexType>

  <xs:simpleType name="name-Type">
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-zA-Z\d\-]{1,100}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="rate-Type">
    <xs:restriction base="xs:string">
      <xs:pattern value="0"/>
      <xs:pattern value="([0-9]+(\.[0-9]*)?)/([smhd])"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="retry-parameters-Type">
    <xs:all>
      <xs:element type="xs:nonNegativeInteger" name="task-retry-limit" maxOccurs="1" minOccurs="0"/>
      <xs:element type="task-age-limit-Type" name="task-age-limit" maxOccurs="1" minOccurs="0"/>
      <xs:element type="nonNegativeDouble" name="min-backoff-seconds" maxOccurs="1" minOccurs="0"/>
      <xs:element type="nonNegativeDouble" name="max-backoff-seconds" maxOccurs="1" minOccurs="0"/>
      <xs:element type="xs:nonNegativeInteger" name="max-doublings" maxOccurs="1" minOccurs="0"/>
    </xs:all>
  </xs:complexType>

  <xs:simpleType name="task-age-limit-Type">
    <xs:restriction base="xs:string">
      <xs:pattern value="([0-9]+(\.?[0-9]*([eE][\-+]?[0-9]+)?)?)([smhd])"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="nonNegativeDouble">
    <xs:restriction base="xs:double">
      <xs:minInclusive value="0"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="target-Type">
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-z\d\-\.]{1,100}"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>
