{#
# Copyright 2017-present Open Networking Foundation
#
# 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.
#}

{# Using regular variables has scoping issues. #}
{# See: https://stackoverflow.com/questions/7537439/how-to-increment-a-variable-on-a-for-loop-in-jinja-template/7537466 #}
{% set counter = {
    'num_service_models': 0,
    'num_service_instance_models': 0,
    'num_orphaned_models': 0,
    } %}
{% macro increment(key) %}
    {% if counter.update({key: counter[key] + 1}) %} {% endif %}
{% endmacro %}
{% for m in proto.messages %}
{% set matched = False %}
{% set base_names = m.bases | map(attribute='name') | list %}
{% if 'Service' in base_names %}
{{ increment('num_service_models') }}
{% set matched = True %}
{% endif %}
{% if not matched and 'ServiceInstance' in base_names or 'Tenant' in base_names or 'TenantWithContainer' in base_names %}
{{ increment('num_service_instance_models') }}
{% set matched = True %}
{% endif %}
{% if not matched and 'XOSBase' not in base_names %}
501 Model does not have a parent - {{ m.name }}
{% endif %}
{% endfor %}
{% if counter.num_service_models !=1 %}
502 {{ counter.num_service_models }} Service models instead of 1
{% elif counter.num_service_instance_models !=1 %}
503 {{ counter.num_service_instance_models }} ServiceInstance models instead of 1
{% else %}
200 OK
{% endif %}
