<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://wadl.dev.java.net/2009/02"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <doc title="Modern Petstore API">
    This is a modern Pet Store API based on the OpenAPI 3.2 specification. It demonstrates contemporary API design patterns and best practices including RESTful compliance, proper HTTP methods, structured error responses (RFC 9457), and modern authentication flows.

Key features include pet catalog browsing, adoption workflow, order management, user accounts, AI-powered chat advisor, and real-time event notifications via webhooks. The API showcases OpenAPI 3.2 capabilities like hierarchical tags, QUERY HTTP method, OAuth device flow, and server-sent events.

Some useful links:
- [API Documentation](https://docs.petstoreapi.com)
- [Source Code Repository](https://github.com/petstoreapi/PetstoreAPI)
- [OpenAPI Specification](https://petstoreapi.com/v1/specs/modern-petstore-3.2.openapi.yaml)
    Version: 1.0.0
  </doc>

  <resources base="https://api.petstoreapi.com/v1">

    <resource path="/pets/{id}">
      <param name="id" style="template" type="xsd:string" required="true">
        <doc>Unique identifier for the pet</doc>
      </param>
      <method name="GET" id="getPet">
        <doc title="Get Pet">Retrieve detailed information about a specific pet.</doc>
        <response status="200">
          <doc>Successful response with pet details</doc>
          <representation mediaType="application/json" element="Pet" />
        </response>
        <response status="400">
        </response>
        <response status="404">
        </response>
        <response status="429">
        </response>
      </method>
      <method name="PUT" id="updatePet">
        <doc title="Update Pet">Update information for an existing pet. Staff only.</doc>
        <request>
          <representation mediaType="application/json" element="Pet" />
        </request>
        <response status="200">
          <doc>Pet updated successfully</doc>
          <representation mediaType="application/json" element="Pet" />
        </response>
        <response status="400">
        </response>
        <response status="401">
        </response>
        <response status="403">
        </response>
        <response status="404">
        </response>
        <response status="422">
        </response>
        <response status="429">
        </response>
      </method>
      <method name="DELETE" id="deletePet">
        <doc title="Delete Pet">Delete a pet from the system. Staff only.</doc>
        <response status="204">
          <doc>Pet deleted successfully</doc>
        </response>
        <response status="400">
        </response>
        <response status="401">
        </response>
        <response status="403">
        </response>
        <response status="404">
        </response>
        <response status="429">
        </response>
      </method>
    </resource>

    <resource path="/pets">
      <method name="GET" id="listPets">
        <doc title="List Pets">Retrieve a paginated list of pets available for adoption with optional filtering.</doc>
        <request>
          <param name="species" style="query" type="xsd:string">
            <doc>Filter by pet species</doc>
          </param>
          <param name="status" style="query" type="xsd:string" default="AVAILABLE">
            <doc>Filter by adoption status</doc>
          </param>
          <param name="ageMin" style="query" type="xsd:int">
            <doc>Minimum age in months</doc>
          </param>
          <param name="ageMax" style="query" type="xsd:int">
            <doc>Maximum age in months</doc>
          </param>
          <param name="size" style="query" type="xsd:string">
            <doc>Filter by pet size</doc>
          </param>
          <param name="goodWithKids" style="query" type="xsd:boolean">
            <doc>Filter pets that are good with children</doc>
          </param>
          <param name="page" style="query" type="xsd:int" default="1">
            <doc>Page number for pagination</doc>
          </param>
          <param name="limit" style="query" type="xsd:int" default="20">
            <doc>Number of items per page</doc>
          </param>
        </request>
        <response status="200">
          <doc>Successful response with pet collection</doc>
          <representation mediaType="application/json" element="PetCollection" />
        </response>
        <response status="400">
        </response>
        <response status="422">
        </response>
        <response status="429">
        </response>
      </method>
      <method name="POST" id="createPet">
        <doc title="Create Pet">Add a new pet to the store catalog, making it available for adoption.

## Pet Lifecycle Workflow

When a new pet enters the system:

1. **Intake**: Staff creates a pet record with this endpoint (status: `available`)
2. **Profile**: Pet details include species, breed, age, medical info, photos, and adoption fee
3. **Discovery**: Pet appears in search results and listings
4. **Adoption Application**: Potential adopters can apply through the adoption endpoints
5. **Adoption**: Once approved, pet status changes to `adopted`
6. **Post-Adoption**: Pet record is retained for historical purposes

**Access**: This operation requires staff permissions (`write:pets` scope or valid Bearer token). Only authenticated staff members can add pets to the system.</doc>
        <request>
          <representation mediaType="application/json" element="Pet" />
        </request>
        <response status="201">
          <doc>Pet created successfully</doc>
          <representation mediaType="application/json" element="Pet" />
        </response>
        <response status="400">
        </response>
        <response status="401">
        </response>
        <response status="422">
        </response>
        <response status="429">
        </response>
      </method>
    </resource>

    <resource path="/chat/completions">
      <method name="POST" id="createChatCompletion">
        <doc title="Create Chat Completion">Creates a model response for a chat conversation with the Pet Adoption Advisor AI. Supports streaming responses using Server-Sent Events (SSE).

## Pet Adoption Advisor

Our AI assistant helps users:
- Get personalized pet recommendations
- Learn about pet care and adoption process
- Answer questions about specific pets
- Provide breed information and compatibility advice

## Streaming Mode

When `stream: true`, the response is sent as Server-Sent Events (SSE), with each token delivered incrementally. This provides a better user experience for longer responses.

### Stream Format

Each chunk is sent as:
```
data: {&quot;id&quot;:&quot;chatcmpl_abc&quot;,&quot;object&quot;:&quot;chat.completion.chunk&quot;,&quot;choices&quot;:[{&quot;delta&quot;:{&quot;content&quot;:&quot;Hello&quot;},&quot;index&quot;:0}]}

```

The stream ends with:
```
data: [DONE]

```

## Non-Streaming Mode

When `stream: false` or omitted, returns a complete response object.</doc>
        <request>
          <representation mediaType="application/json" />
        </request>
        <response status="201">
          <doc>Successful response. Format depends on the `stream` parameter.</doc>
          <representation mediaType="text/event-stream" />
          <representation mediaType="application/json" />
        </response>
        <response status="400">
        </response>
        <response status="401">
        </response>
        <response status="422">
        </response>
        <response status="429">
        </response>
      </method>
    </resource>

    <resource path="/pets/{id}/images">
      <method name="POST" id="uploadPetPhoto">
        <doc title="Upload Pet Image">Upload an image for the specified pet. Requires authentication and write:pets permission.</doc>
        <request>
          <representation mediaType="multipart/form-data" />
        </request>
        <response status="201">
          <doc>Operation successful</doc>
          <representation mediaType="application/json" element="ApiResponse" />
        </response>
        <response status="401">
        </response>
        <response status="404">
        </response>
      </method>
    </resource>

    <resource path="/orders/{id}/payment">
      <method name="POST" id="createOrderPayment">
        <doc title="Pay Order">Process payment for an existing order.

## Payment Workflow

Payment processing follows this workflow:

1. **Create Order**: First create an order using `POST /orders` (status: `placed`)
2. **Submit Payment**: Call this endpoint with payment details (card or bank account)
3. **Payment Processing**: The payment is processed with status `processing`
4. **Payment Result**:
   - **Success**: Payment status becomes `succeeded`, order status updates to `approved`
   - **Failure**: Payment status becomes `failed`, order remains `placed` and can be retried
5. **Receipt**: After successful payment, retrieve the receipt from the order details

**Security Note**: Sensitive payment data (like CVC codes) are `writeOnly` and never returned in responses. Card numbers and account numbers are masked when read.</doc>
        <request>
          <representation mediaType="application/json" element="OrderPayment" />
        </request>
        <response status="201">
          <doc>Payment successful</doc>
          <representation mediaType="application/json" element="OrderPayment" />
        </response>
        <response status="400">
        </response>
        <response status="404">
        </response>
        <response status="422">
        </response>
      </method>
    </resource>

    <resource path="/inventories">
      <method name="GET" id="getInventory">
        <doc title="List Inventory">Returns a mapping of status codes to quantities.</doc>
        <request>
          <param name="status" style="query" type="xsd:string" repeating="true">
            <doc>Values to filter inventory status (comma-separated).</doc>
          </param>
        </request>
        <response status="200">
          <doc>Operation successful</doc>
          <representation mediaType="application/json" />
        </response>
      </method>
    </resource>

    <resource path="/orders">
      <method name="POST" id="createOrder">
        <doc title="Create Order">Create a new order in the store.</doc>
        <request>
          <representation mediaType="application/json" element="Order" />
        </request>
        <response status="201">
          <doc>Operation successful</doc>
          <representation mediaType="application/json" element="Order" />
        </response>
        <response status="400">
        </response>
        <response status="404">
        </response>
        <response status="422">
        </response>
      </method>
    </resource>

    <resource path="/orders/{id}">
      <param name="id" style="template" type="xsd:string" required="true">
        <doc>Unique identifier for the order</doc>
      </param>
      <method name="GET" id="getOrder">
        <doc title="Get Order">Retrieve order information by order ID.</doc>
        <response status="200">
          <doc>Operation successful</doc>
          <representation mediaType="application/json" element="Order" />
        </response>
        <response status="400">
        </response>
        <response status="404">
        </response>
      </method>
      <method name="POST" id="callbackOrder">
        <doc title="Callback Example">Handles order events and supports asynchronous processing with Callback.</doc>
        <request>
          <representation mediaType="application/json" />
        </request>
        <response status="201">
          <doc>Callback enqueued successfully.</doc>
          <representation mediaType="application/json" />
        </response>
        <response status="400">
        </response>
        <response status="404">
        </response>
      </method>
      <method name="DELETE" id="deleteOrder">
        <doc title="Delete Order">Delete an existing order by its unique identifier.</doc>
        <response status="204">
          <doc>Resource deleted successfully</doc>
        </response>
        <response status="400">
        </response>
        <response status="404">
        </response>
      </method>
    </resource>

    <resource path="/users">
      <method name="POST" id="createUser">
        <doc title="Create User">Create a new user in the system.</doc>
        <request>
          <representation mediaType="application/json" element="User" />
        </request>
        <response status="201">
          <doc>User created successfully.</doc>
          <representation mediaType="application/json" />
        </response>
        <response status="400">
        </response>
        <response status="422">
        </response>
        <response status="500">
        </response>
      </method>
    </resource>

    <resource path="/users/{id}">
      <param name="id" style="template" type="xsd:string" required="true">
        <doc>Unique identifier for the user</doc>
      </param>
      <method name="GET" id="getUserById">
        <doc title="Get User">Retrieve user information by user ID.</doc>
        <response status="200">
          <doc>Operation successful</doc>
          <representation mediaType="application/json" element="User" />
        </response>
        <response status="400">
        </response>
        <response status="404">
        </response>
      </method>
      <method name="PUT" id="updateUser">
        <doc title="Update User">Update user information. Only the logged-in user can perform this operation.</doc>
        <request>
          <representation mediaType="application/json" element="User" />
        </request>
        <response status="200">
          <doc>User updated successfully.</doc>
          <representation mediaType="application/json" />
        </response>
        <response status="400">
        </response>
        <response status="404">
        </response>
        <response status="422">
        </response>
      </method>
      <method name="DELETE" id="deleteUser">
        <doc title="Delete User">Delete a user account. Only the logged-in user can perform this operation.</doc>
        <response status="204">
          <doc>Resource deleted successfully</doc>
        </response>
        <response status="400">
        </response>
        <response status="404">
        </response>
      </method>
    </resource>

    <resource path="/auth/tokens">
      <method name="POST" id="createToken">
        <doc title="Create Token (Login)">Authenticate user and obtain an access token.</doc>
        <request>
          <representation mediaType="application/json" />
        </request>
        <response status="200">
          <doc>Login successful</doc>
          <representation mediaType="application/json" />
        </response>
        <response status="401">
        </response>
        <response status="422">
        </response>
        <response status="429">
        </response>
      </method>
    </resource>

  </resources>

  <!-- Schema definitions -->
  <!-- Note: Full schema conversion requires additional processing -->
  <!-- Schemas: Pet, PetCollection, User, OrderPayment, CardPaymentSource, BankAccountPaymentSource, Category, Links, Order, ApiResponse, Tag, Error -->

</application>
