{
  "openapi": "3.0.3",
  "info": {
    "title": "Iced Latte Order API",
    "description": "API for managing orders, including retrieving and placing orders. Supports filtering orders by status and provides detailed order information.",
    "version": "1.0.0",
    "contact": {
      "name": "Iced Latte Support",
      "email": "zufar.sunagatov@gmail.com",
      "url": "https://github.com/Sunagatov/Iced-Latte"
    },
    "license": {
      "name": "MIT",
      "url": "https://github.com/Sunagatov/Iced-Latte/blob/main/LICENSE"
    }
  },
  "servers": [
    {
      "url": "http://localhost:8083",
      "description": "Local development server"
    },
    {
      "url": "https://iced-latte.uk/backend",
      "description": "Production server"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Orders",
      "description": "Operations related to orders."
    }
  ],
  "paths": {
    "/api/v1/orders": {
      "get": {
        "tags": [
          "Orders"
        ],
        "summary": "Retrieve orders for the authorized user based on status",
        "description": "Fetches all orders for the authenticated user, optionally filtered by status codes.",
        "operationId": "getOrders",
        "parameters": [
          {
            "name": "status",
            "description": "Filter orders by status. Multiple status codes can be provided as an array.",
            "in": "query",
            "required": false,
            "schema": {
              "type": "array",
              "items": {
                "$ref": "#/components/schemas/OrderStatus"
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of orders successfully retrieved. Returns an empty array if no orders match the criteria.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/OrderDto"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid query parameters.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized access.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Orders"
        ],
        "summary": "Place a new order for the authorized user",
        "description": "Creates a new order for the authenticated user. Requires address and recipient information.",
        "operationId": "createOrder",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateNewOrderRequestDto"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Order successfully placed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderDto"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized access.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "JWT token for authenticated requests"
      }
    },
    "schemas": {
      "OrderStatus": {
        "type": "string",
        "description": "The status of an order.",
        "enum": [
          "CREATED",
          "PAID",
          "DELIVERY",
          "FINISHED"
        ]
      },
      "CreateNewOrderRequestDto": {
        "type": "object",
        "description": "Details required to create a new order.",
        "required": [
          "address",
          "recipientName",
          "recipientSurname"
        ],
        "properties": {
          "address": {
            "$ref": "./user-openapi.yaml#/components/schemas/AddressDto"
          },
          "recipientName": {
            "type": "string",
            "description": "Name of the order recipient. Can be different from the user's name."
          },
          "recipientSurname": {
            "type": "string",
            "description": "Surname of the order recipient. Can be different from the user's surname."
          }
        }
      },
      "OrderDto": {
        "type": "object",
        "description": "Represents an order in the system.",
        "required": [
          "id",
          "status",
          "createdAt"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Unique identifier for the order."
          },
          "status": {
            "$ref": "#/components/schemas/OrderStatus"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "The date and time when the order was created."
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "description": "Standard error response format",
        "required": [
          "message",
          "timestamp",
          "status"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "Error message"
          },
          "details": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Additional error details"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time",
            "description": "Error timestamp"
          },
          "status": {
            "type": "integer",
            "description": "HTTP status code"
          },
          "path": {
            "type": "string",
            "description": "Request path that caused the error"
          }
        }
      }
    }
  }
}