{#
Bengal OpenAPI Request Body
===========================

Displays request body information including:
- Content type badges
- Description
- Schema viewer (for object types)

Context:
- request_body: OpenAPIRequestBodyMetadata or dict with:
  - content_type: Media type (e.g., "application/json")
  - schema_ref: Reference to schema
  - required: bool
  - description: Description
  - schema: Inline schema object (optional)

Kida Features:
- {% with %} for nil-safe optional sections
- {% spaceless %} for compact badge output
- Optional chaining (?.) and null coalescing (??)
#}
{% let content_type = request_body?.content_type ?? 'application/json' %}
{% let is_required = request_body?.required ?? false %}
{% let description = request_body?.description ?? '' %}
{% let schema_ref = request_body?.schema_ref %}
{% let inline_schema = request_body?.schema %}

<section class="api-request-body autodoc-section" data-section="request-body">
  <header class="api-request-body__header">
    <h2 class="api-request-body__title autodoc-section-title">Request Body</h2>

    <div class="api-request-body__meta">
      {% spaceless %}
      {% if is_required %}
      <span class="badge badge--danger-subtle badge--sm">required</span>
      {% end %}
      <span class="badge badge--outline badge--sm">{{ content_type }}</span>
      {% end %}
    </div>
  </header>

  {# Description #}
  {% if description %}
  <div class="api-request-body__description prose-sm">
    {{ description | markdownify | safe }}
  </div>
  {% end %}

  {# Schema Reference Link #}
  {% with schema_ref as ref %}
  {% let schema_name = ref | split('#/components/schemas/') | last %}
  <div class="api-request-body__schema-ref">
    <span class="api-request-body__label">Schema:</span>
    <a href="#schema-{{ schema_name | slugify }}" class="api-request-body__schema-link">
      <code>{{ schema_name }}</code>
    </a>
  </div>
  {% end %}

  {# Inline Schema Viewer #}
  {% with inline_schema as s %}
  {% let schema = s %}
  {% let depth = 0 %}
  {% include 'autodoc/openapi/partials/schema-viewer.html' %}
  {% end %}
</section>
