<!--

    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you 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.

-->
{% assign proto = site.data.protobuf.files[0] %}
{% assign messages = proto.messages %}
{% assign enums = proto.enums %}
{% assign atomic_types = "bool,bytes,double,int32,string,uint32,uint64" | split: "," %}

<div class="protobuf">
  <div class="container">
    <div class="row">
      <div class="col col-sm-6 padding-0">
        <p class="lead protobuf-title">Messages</p>
        <ul>
          {% for message in messages %}
          <li>
            <a href="#{{ message.fullName }}">
              {{ message.name }}
            </a>
          </li>
          {% endfor %} <!-- for message in messages -->
        </ul>
      </div>
      <div class="col col-sm-6 padding-0">
        <p class="lead protobuf-title">Enums</p>
        <ul>
          {% for enum in enums %}
          <li>
            <a href="#{{ enum.fullName }}">
              {{ enum.name }}
            </a>
          </li>
          {% endfor %} <!-- for enum in enums -->
        </ul>
      </div>
    </div>
  </div>

  <h3>Protobuf messages</h3>

  <div class="card messages">
    {% for message in messages %}{% assign fields = message.fields %}
    <div class="card-block">
      <div class="card-title">
        <h5 class="message-name" id="{{ message.fullName }}">
          {{ message.name }}
        </h5>
        <p class="message-name">{{ message.fullName }}</p>
        {% if message.description %}<p class="lead">{{ message.description }}</p>{% endif %}
      </div>
      {% if message.hasFields %}
      <div class="card">
        <h5>Fields</h5>
        <table class="protobuf-table">
          <thead>
            <tr>
              <th>Name</th>
              <th>Type</th>
              <th>Label</th>
              <th>Default</th>
              <th>Description</th>
            </tr>
          </thead>
          <tbody>
            {% for field in fields %}
            <tr>
              <td class="wrap">{{ field.name }}</td>
              {% if atomic_types contains field.type %}
              <td class="wrap">{{ field.type }}</td>
              {% else %}
              <td class="wrap"><a href="#{{ field.fullType }}">{{ field.type }}</a></td>
              {% endif %}
              <td>{{ field.label }}</td>
              <td>{{ field.defaultValue }}</td>
              <td>{{ field.description }}</td>
            </tr>
            {% endfor %} <!-- for field in fields -->
          </tbody>
        </table>
      </div>
      {% else %}
      <p>This message has no fields.</p>
      {% endif %} <!-- if fields -->
    </div>
    {% endfor %} <!-- for message in messages -->
  </div>

  <h3>Protobuf enums</h3>

  <div class="card enums">
    {% for enum in enums %}{% assign values = enum.values %}
    <div class="card-block">
      <div class="card-title">
        <h5 class="enum-name" id="{{ enum.fullName }}">{{ enum.name }}</h5>
        {% if enum.description %}<p class="lead">{{ enum.description | markdownify }}</p>{% endif %}
      </div>
      <div class="card">
        <h5>Enum values</h5>
        <table class="protobuf-table">
          <thead>
            <tr>
              <th>Name</th>
              <th>Number</th>
              <th>Description</th>
            </tr>
          </thead>
          <tbody>
            {% for value in values %}
            <tr>
              <td>{{ value.name }}</td>
              <td>{{ value.number }}</td>
              <td>{{ value.description | markdownify }}</td>
            </tr>
            {% endfor %} <!-- for value in values -->
          </tbody>
        </table>
      </div>
    </div>
    {% endfor %} <!-- for enum in enums -->
  </div>
</div>