{
  "openapi": "3.1.0",
  "info": {
    "title": "Cafecito ordering API",
    "version": "1.0.0",
    "description": "Order specialty coffee for hand delivery. Quote first, show the person the total, and only place the order after they approve it. The person (or their agent's Link wallet, with their approval) pays at payment_url."
  },
  "servers": [
    {
      "url": "https://cafecito.bot"
    }
  ],
  "paths": {
    "/api/v1/coffees": {
      "get": {
        "operationId": "searchCoffee",
        "summary": "Search the catalog",
        "parameters": [
          {
            "name": "query",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "roaster",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "roast",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "form",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "max_price",
            "in": "query",
            "schema": {
              "type": "number"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching in-stock bags"
          }
        }
      }
    },
    "/api/v1/coffees/{id}": {
      "get": {
        "operationId": "getCoffee",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One bag"
          },
          "404": {
            "description": "Problem (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/delivery": {
      "get": {
        "operationId": "getDeliveryInfo",
        "summary": "Cities, ZIPs, fees, days and cutoff",
        "responses": {
          "200": {
            "description": "Delivery rules"
          }
        }
      }
    },
    "/api/v1/quotes": {
      "post": {
        "operationId": "quoteOrder",
        "summary": "Price an order without placing it",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "items",
                  "city"
                ],
                "properties": {
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "id"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "quantity": {
                          "type": "integer",
                          "minimum": 1,
                          "default": 1
                        }
                      }
                    }
                  },
                  "city": {
                    "type": "string",
                    "enum": [
                      "San Francisco",
                      "Berkeley",
                      "Lafayette",
                      "Walnut Creek"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Quote with total, delivery date and pilot_notice"
          },
          "422": {
            "description": "Problem (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/feedback": {
      "post": {
        "operationId": "sendFeedback",
        "summary": "Tell Cafecito what the person wanted and couldn't do here (no personal details)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "wanted"
                ],
                "properties": {
                  "wanted": {
                    "type": "string"
                  },
                  "blocked_by": {
                    "type": "string"
                  },
                  "agent": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Received"
          },
          "422": {
            "description": "Problem (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "sendFeedbackByLink",
        "summary": "The same report as query parameters, for agents that can only fetch pages",
        "parameters": [
          {
            "name": "wanted",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "blocked_by",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "agent",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Received"
          },
          "422": {
            "description": "Problem (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/orders": {
      "post": {
        "operationId": "placeOrder",
        "summary": "Place an order the person approved; returns payment_url",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "items",
                  "customer_name",
                  "street_address",
                  "city",
                  "zip_code",
                  "expected_total"
                ],
                "properties": {
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "id"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "quantity": {
                          "type": "integer",
                          "minimum": 1,
                          "default": 1
                        }
                      }
                    }
                  },
                  "customer_name": {
                    "type": "string"
                  },
                  "street_address": {
                    "type": "string"
                  },
                  "city": {
                    "type": "string",
                    "enum": [
                      "San Francisco",
                      "Berkeley",
                      "Lafayette",
                      "Walnut Creek"
                    ]
                  },
                  "zip_code": {
                    "type": "string"
                  },
                  "expected_total": {
                    "type": "number",
                    "description": "The quoted total the person approved"
                  },
                  "expected_delivery_date": {
                    "type": "string",
                    "format": "date",
                    "description": "The quoted delivery_date; refused if the cutoff passed since"
                  },
                  "phone": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string"
                  },
                  "delivery_notes": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Order awaiting payment, with payment_url"
          },
          "422": {
            "description": "Problem (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Problem (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Problem (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/orders/{order_id}": {
      "get": {
        "operationId": "getOrderStatus",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Order status"
          },
          "404": {
            "description": "Problem (RFC 9457)",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          }
        }
      }
    }
  }
}