<!DOCTYPE html>
<html lang="en">
<head>
    <title>{{ specification.entity_name }} API Reference {{ apiversion }}</title>
    <link rel="stylesheet" href="../css/bootstrap.css">
    <link rel="stylesheet" href="../css/style.css">
</head>

<body data-spy="scroll" data-target="#navbarmain">

    <nav class="navbar navbar-default navbar-fixed-top" id="navbarmain">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="index.html">{{ product_name }} API Documentation {{ apiversion }}</a>
            </div>
            <div class="collapse navbar-collapse" id="navbar">
                <ul class="nav navbar-nav">
                    <li><a data-id="intro" href="#intro">Top</a></li>
                    <li><a data-id="overview" href="#overview">Overview</a></li>
                    <li><a data-id="apiresources" href="#apiresources">API Resource</a></li>
                    <li><a data-id="parents" href="#parents">Parents</a></li>
                    <li><a data-id="children" href="#children">Children</a></li>
                    <li><a data-id="members" href="#members">Members</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Attributes <span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            {% for attribute in specification.attributes|sort(attribute='local_name') %}
                            <li><a data-id="attr_{{ attribute.name }}" href="#attr_{{ attribute.name }}" class="fixed-text">{{ attribute.name }}</a></li>
                            {% endfor %}
                        </ul>
                    </li>
                </ul>
                <form class="navbar-form navbar-right" role="search">
                    <div class="form-group dropdown">
                        <input type="text" class="form-control" placeholder="Search" id="searchfield">
                        <ul class="dropdown-menu dropdown-menu-left" role="menu" id="searchresult" style="display: none"></ul>
                    </div>
                </form>
            </div>
        </div>
    </nav>

    {# macro to create a method label #}
    {% macro label_for_method(method) %}
    {% if method == "GET" %}
    {% set label_class = "label-default" %}
    {% elif method == "POST" %}
    {% set label_class = "label-primary" %}
    {% elif method == "PUT" %}
    {% set label_class = "label-success" %}
    {% elif method == "DELETE" %}
    {% set label_class = "label-danger" %}
    {% endif %}
    <span class="label {{ label_class }}">{{ method.lower()}}</span>
    {% endmacro %}

    {# macro to create allowed_choices list #}
    {% macro string_for_allowed_choices(attribute) %}
    {% set allowed = [] %}
    {% set allowed_values = "" %}
    {% if attribute.allowed_choices %}
    {% for value in attribute.allowed_choices|sort %}
    {% do allowed.append(value) %}
    {% endfor %}
    {% if allowed|count > 0 %}
    {% set allowed_values = " (" + allowed|join(" | ") + ")" %}
    {% endif %}
    {% endif %}
    {{ allowed_values }}
    {% endmacro %}

    {# macro for creating attribute labels #}
    {% macro tokens_for_attribute(attribute) %}
    {% if attribute.required %}
     <span class="label label-danger"> required </span>&nbsp;
    {% endif %}
    {% if attribute.read_only %}
     <span class="label label-warning"> read only </span>&nbsp;
    {% endif %}
    {% if attribute.deprecated %}
     <span class="label label-default"> deprecated </span>&nbsp;
    {% endif %}
    {% if attribute.creation_only %}
     <span class="label label-info"> creation only </span>&nbsp;
    {% endif %}
    {% if attribute.autogenerated %}
     <span class="label label-info"> autogenerated </span>&nbsp;
    {% endif %}
    {% if attribute.filterable %}
     <span class="label label-info"> filterable </span>&nbsp;
    {% endif %}
    {% if attribute.orderable %}
     <span class="label label-info"> orderable </span>&nbsp;
    {% endif %}
    {% if attribute.unique %}
    {% if attribute.unique_scope == "global" %}
     <span class="label label-warning"> globally unique </span>&nbsp;
    {% else %}
     <span class="label label-warning"> locally unique </span>&nbsp;
    {% endif %}
    {% endif %}
    {% endmacro %}

    {# macro to create api list #}
    {% macro make_api_list(mode, nothing_string) %}
    {% if mode == "children" %}
    {% set apis = child_apis %}
    {% elif mode == "members" %}
    {% set apis = member_apis %}
    {% elif mode == "parents" %}
    {% set apis = parent_apis %}
    {% else %}
    {% set apis = self_apis %}
    {% endif %}

    {% if apis|count and specification.resource_name != None %}
    {% for api in apis %}
    <div class="row bordered-row">
        <div class="col-xs-7">

            {% if mode == "parents" %}
            {% if api.relationship == "root" %}
            <span class="fixed-text">/{{ specification.resource_name }}</a>
            {% else %}
            <span class="fixed-text">/<a href="{{ api.remote_spec.rest_name }}.html">{{ api.remote_spec.resource_name }}</a>/<span class="text-muted">id</span>/{{ specification.resource_name }}</span>
            {% endif %}

            {% elif mode == "children" or mode == "members" %}

            {% if api.relationship == "root" %}
            <span class="fixed-text">/<a href="{{ api.remote_spec.rest_name }}.html">{{ api.remote_spec.resource_name }}</a></span>
            {% else%}
            <span class="fixed-text">/{{ specification.resource_name }}/<span class="text-muted">id</span>/<a href="{{ api.remote_spec.rest_name }}.html">{{ api.remote_spec.resource_name }}</a></span>
            {% endif %}

            {% else %}
            <span class="fixed-text">/{{ specification.resource_name }}/<span class="text-muted">id</span></a>
            {% endif %}
        </div>
        <div class="col-xs-5 text-right">
            {% for action in api.actions|sort() %}
            {{ label_for_method(action)}}
            {% endfor %}
        </div>
    </div>
    {% endfor %}
    {% else %}
    <p>{{ nothing_string }}</p>
    {% endif %}
    {% endmacro %}


    <div class="container">

        <section id="intro">
            <h2>{{ specification.entity_name }}</h2>
            <p>{{ specification.description }}</p>
        </section>

        <section id="overview">
            <h3>Overview</h3>
                <table class="width: 100%">
                    {% for attribute in specification.attributes|sort(attribute='local_name') %}
                    <tr>
                        <td class="fixed-text">
                            <a href="#attr_{{ attribute.name }}" title="{{ attribute.description }}">{{ attribute.name }}</a>
                        </td>
                        <td style="padding-left: 10px;" class="fixed-text hide-xs">
                            <span class="type_{{ attribute.type }}">{{ attribute.type }}{{ string_for_allowed_choices(attribute)}}</span>
                        </td>
                        <td style="padding-left: 30px;" class="fixed-text hide-xs">
                            {{ tokens_for_attribute(attribute) }}
                        </td>
                    </tr>
                    {% endfor %}
                </table>
        </section>

        <section id="apiresources">
            <h3>API Resource</h3>
            {{ make_api_list("self", "This is an embedded object that can not be directly accessed.")}}
        </section>

        <section id="parents">
            <h3>Parents</h3>
            {{ make_api_list("parents", "This object has no parents.")}}
        </section>

        <section id="children">
            <h3>Children</h3>
            {{ make_api_list("children", "This object has no children.")}}
        </section>

        <section id="members">
            <h3>Members</h3>
            {{ make_api_list("members", "This object has no members.")}}
        </section>

        <section id="attributes">
            <h3>Attributes documentation</h3>
            {% for attribute in specification.attributes|sort(attribute='local_name') %}
            <section id="attr_{{ attribute.name }}" class="filterable" data-filter-keyword="{{ attribute.name }}" style="padding-top: 60px; margin-top: -60px;">
                <div class="panel panel-default">
                    <div class="panel-heading fixed-text">
                        <b>{{ attribute.name }}</b>
                        <span class="type_{{ attribute.type }} fixed-text">{{ attribute.type }}</span>
                        {{ tokens_for_attribute(attribute) }}
                    </div>

                    <div class="panel-body">
                        <h5><b>Discussion</b></h5>
                        <p>{{ attribute.description }}</p>

                        <hr/>

                        <h5><b>Charateristics</b></h5>
                        <p>
                            {% if attribute.allowed_choices %}
                            <span class="small"><b>Allowed values: </b></span><span class="fixed-text">{{ attribute.allowed_choices|sort|join(", ") }}</span><br/>
                            {% endif %}

                            {% if attribute.allowed_chars %}
                            <span class="small"><b>Allowed characters: </b></span><span class="fixed-text">{{ attribute.allowed_chars }}</span><br/>
                            {% endif %}

                            {% if attribute.default_value %}
                            <span class="small"><b>Default value: </b></span><span class="fixed-text">{{ attribute.default_value }}</span><br/>
                            {% endif %}

                            {% if attribute.format %}
                            <span class="small"><b>Format: </b></span><span class="fixed-text">{{ attribute.format }}</span><br/>
                            {% endif %}

                            {% if attribute.min_length %}
                            <span class="small"><b>Min lenght: </b></span><span class="fixed-text">{{ attribute.min_length }}</span><br/>
                            {% endif %}

                            {% if attribute.max_length %}
                            <span class="small"><b>Max lenght: </b></span><span class="fixed-text">{{ attribute.max_length }}</span><br/>
                            {% endif %}

                            {% if attribute.min_value %}
                            <span class="small"><b>Min value: </b></span><span class="fixed-text">{{ attribute.min_value }}</span><br/>
                            {% endif %}

                            {% if attribute.max_value %}
                            <span class="small"><b>Max value: </b></span><span class="fixed-text">{{ attribute.max_value }}</span><br/>
                            {% endif %}

                            <span class="small"><b>SDK attribute: </b></span><span class="fixed-text">{{ attribute.local_name }}</span>
                        </p>
                    </div>
                </div>
            </section>
            {% endfor %}
        </section>

    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <script src="../js/search.js"></script>
    <script>
        $(document).ready(function()
        {
            initialize_search("attr_");
            initialize_scrollspy();
        });
    </script>

</body>
</html>
