{#-
Response Schemas Component

Renders response information including status codes, schemas, and examples.
Handles multiple response types and error responses safely.
-#}

{% from 'macros/safe_macros.md.jinja2' import safe_section, safe_render, safe_for %}
{% from 'macros/code_blocks.md.jinja2' import code_block %}

{% if element.metadata.responses %}
{% call safe_section("response_schemas") %}
## Responses

{% call safe_for(element.metadata.responses.items(), "*No responses defined.*") %}
{% set status_code = item[0] %}
{% set response_info = item[1] %}

### {{ status_code }} - {{ response_info.description | default('Response') }}

{% if response_info.description %}
{{ response_info.description }}
{% endif %}

{% if response_info.headers %}
**Headers:**

{% call safe_for(response_info.headers.items(), "*No headers defined.*") %}
{% set header_name = item[0] %}
{% set header_info = item[1] %}

- **`{{ header_name }}`**{% if header_info.description %}: {{ header_info.description }}{% endif %}
  {% if header_info.schema %}(Type: `{{ header_info.schema.type | default('string') }}`){% endif %}

{% endcall %}
{% endif %}

{% if response_info.content %}
**Content Types:**

{% call safe_for(response_info.content.items(), "*No content types defined.*") %}
{% set content_type = item[0] %}
{% set content_info = item[1] %}

#### `{{ content_type }}`

{% if content_info.schema %}
**Schema:**

{{ code_block(content_info.schema | tojson(indent=2), 'json', 'Response Schema') }}
{% endif %}

{% if content_info.example %}
**Example:**

{{ code_block(content_info.example | tojson(indent=2), 'json', 'Response Example') }}
{% endif %}

{% if content_info.examples %}
**Examples:**

{% call safe_for(content_info.examples.items(), "*No examples provided.*") %}
{% set example_name = item[0] %}
{% set example_data = item[1] %}

##### {{ example_name | title }}

{% if example_data.summary %}
{{ example_data.summary }}
{% endif %}

{% if example_data.description %}
{{ example_data.description }}
{% endif %}

{{ code_block(example_data.value | tojson(indent=2), 'json') }}

{% endcall %}
{% endif %}

{% endcall %}
{% endif %}

{% endcall %}
{% endcall %}
{% endif %}
