# -*- coding: utf-8 -*-

from flask import Blueprint
from flask_restful import Api
{%- for item in config %}
from . import {{item["name"]}}
{%- endfor %}

api_v1 = Blueprint('api_v1', __name__)

api = Api(api_v1)

{%- for item in config %}
{%- if "restful" in item.get("view") and item.get("view").get("restful") == False %}
{%- for r in item.get("view").get("routes", []) %}
api.add_resource({{ item['name'] }}.{{ r.get('name') | capitalize }}, '{{ r.get("path") }}')
{%- endfor %}
{%- else %}
api.add_resource({{ item['name'] }}.{{ item['name'] | letterUpper }}Resource, '/{{ item['name'] }}{{ item['view']['get']['path'] }}'{% if item['view']['get']['endpoint'] %}, endpoint={{ item['view']['get']['endpoint'] }}{% endif %})
api.add_resource({{ item['name'] }}.{{ item['name'] | letterUpper }}ResourceList, '/{{ item['name'] }}{{ item['view']['getList']['path'] }}'{% if item['view']['getList']['endpoint'] %}, endpoint='{{ item['view']['getList']['endpoint'] }}'{% endif %})
{%- endif %}
{% endfor %}