{
  "openapi": "3.1.0",
  "info": {
    "title": "Community Food API // Universe Engine",
    "version": "1.0.0",
    "description": "Headless culinary commerce, dynamic unit economics, station portion telemetry, and e-cargo spatial batch consolidation."
  },
  "servers": [
    {
      "url": "https://api.community.nyc",
      "description": "Production Edge Workers Endpoint"
    },
    {
      "url": "/v1",
      "description": "Relative Pages Functions Endpoint"
    }
  ],
  "paths": {
    "/v1/pricing/calculate": {
      "post": {
        "summary": "Dynamic Unit Economics Engine",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "chef_id",
                  "sku",
                  "cogs_usd",
                  "packaging_usd",
                  "target_net_margin",
                  "fulfillment_mode"
                ],
                "properties": {
                  "chef_id": {
                    "type": "string",
                    "example": "chef_kenji_02"
                  },
                  "sku": {
                    "type": "string",
                    "example": "kn-cod-01"
                  },
                  "cogs_usd": {
                    "type": "number",
                    "example": 6.8
                  },
                  "packaging_usd": {
                    "type": "number",
                    "example": 0.95
                  },
                  "station_amortized_usd": {
                    "type": "number",
                    "example": 1.4
                  },
                  "fulfillment_mode": {
                    "type": "string",
                    "enum": [
                      "PICKUP",
                      "ECARGO_BATCH"
                    ]
                  },
                  "distance_miles": {
                    "type": "number",
                    "example": 1.1
                  },
                  "target_net_margin": {
                    "type": "number",
                    "example": 0.55
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic price output",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "menu_price_usd": {
                      "type": "number",
                      "example": 24.0
                    },
                    "api_execution_fee_usd": {
                      "type": "number",
                      "example": 1.25
                    },
                    "courier_fee_usd": {
                      "type": "number",
                      "example": 3.0
                    },
                    "stripe_rail_usd": {
                      "type": "number",
                      "example": 1.0
                    },
                    "chef_net_payout_usd": {
                      "type": "number",
                      "example": 18.75
                    },
                    "chef_net_profit_usd": {
                      "type": "number",
                      "example": 9.6
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/inventory/sync": {
      "post": {
        "summary": "Bi-directional Kitchen Station Portion Telemetry",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "node_id",
                  "chef_id",
                  "sku",
                  "delta",
                  "idempotency_key"
                ],
                "properties": {
                  "node_id": {
                    "type": "string",
                    "example": "bk-02"
                  },
                  "chef_id": {
                    "type": "string",
                    "example": "chef_kenji_02"
                  },
                  "sku": {
                    "type": "string",
                    "example": "kn-cod-01"
                  },
                  "delta": {
                    "type": "integer",
                    "example": -1
                  },
                  "idempotency_key": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "State lock & Edge CDN purge trigger",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sku": {
                      "type": "string"
                    },
                    "remaining_portions": {
                      "type": "integer",
                      "example": 13
                    },
                    "state": {
                      "type": "string",
                      "enum": [
                        "IN_STOCK",
                        "LOW_STOCK",
                        "LOCKED_SOLD_OUT"
                      ]
                    },
                    "cdn_surrogate_purged": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/dispatch/batch": {
      "post": {
        "summary": "Multi-Chef Spatial Batch Consolidation",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "node_id",
                  "window_close_iso",
                  "orders"
                ],
                "properties": {
                  "node_id": {
                    "type": "string",
                    "example": "bk-02"
                  },
                  "window_close_iso": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "orders": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "order_id": {
                          "type": "string"
                        },
                        "chef_id": {
                          "type": "string"
                        },
                        "prep_complete_iso": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "dropoff_lat": {
                          "type": "number"
                        },
                        "dropoff_lon": {
                          "type": "number"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Unified e-cargo route manifest",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "batch_id": {
                      "type": "string",
                      "example": "batch_bk02_1830"
                    },
                    "courier_id": {
                      "type": "string",
                      "example": "ecargo_09"
                    },
                    "consolidated_orders_count": {
                      "type": "integer",
                      "example": 4
                    },
                    "route_sequence": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "total_route_miles": {
                      "type": "number",
                      "example": 2.4
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}