{
  "openapi": "3.1.0",
  "info": {
    "title": "OpenQloud Management API",
    "version": "1.0.0",
    "description": "Manage an existing restaurant connection: read its details, update its configuration, and explicitly validate the provider connection. Validation contacts the configured provider endpoint; saving configuration alone does not."
  },
  "tags": [
    {
      "name": "Connections",
      "description": "Existing restaurant installations visible to the authenticated developer account."
    },
    {
      "name": "Configuration",
      "description": "Read or update module-declared connection settings. Secret values are never returned."
    },
    {
      "name": "Validation",
      "description": "Inspect validation state or explicitly call the integration's configured validation actions."
    }
  ],
  "security": [
    {
      "LegacyServerAccessToken": []
    }
  ],
  "paths": {
    "/management-api/v1/restaurants/{sellingPointId}/connections": {
      "get": {
        "tags": [
          "Connections"
        ],
        "operationId": "legacyListRestaurantConnections",
        "summary": "List existing connections for a restaurant",
        "description": "Returns non-disabled module setups for the requested restaurant that belong to the authenticated developer account. This endpoint does not create installations. Results are paginated.",
        "security": [
          {
            "LegacyServerAccessToken": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/SellingPointId"
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Page of authorized existing connections.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectionListResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidRestaurant"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/management-api/v1/restaurants/{sellingPointId}/connections/{connectionId}/configuration": {
      "get": {
        "tags": [
          "Configuration"
        ],
        "operationId": "legacyGetConnectionConfiguration",
        "summary": "Read connection configuration",
        "description": "Returns module-declared settings. Secret-like values are masked: value is null and only the configured flag is returned for those fields.",
        "security": [
          {
            "LegacyServerAccessToken": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/SellingPointId"
          },
          {
            "$ref": "#/components/parameters/ConnectionId"
          }
        ],
        "responses": {
          "200": {
            "description": "Configuration for the authorized connection.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConfigurationResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/ConnectionNotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Configuration"
        ],
        "operationId": "legacyPatchConnectionConfiguration",
        "summary": "Update connection configuration",
        "description": "Partially updates module-declared fields and, when enabled for the module, providerClientId. Unknown fields are rejected. A changed configuration clears previous validated/connected flags. Saving does not call the provider or send normal restaurant events.",
        "security": [
          {
            "LegacyServerAccessToken": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/SellingPointId"
          },
          {
            "$ref": "#/components/parameters/ConnectionId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ConfigurationPatch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated configuration (secret values remain masked).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConfigurationResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidConfiguration"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "The provider client ID cannot be edited for this module.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/ConnectionNotFound"
          },
          "413": {
            "description": "Request body exceeds 64 KiB.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/management-api/v1/restaurants/{sellingPointId}/connections/{connectionId}/validation": {
      "get": {
        "tags": [
          "Validation"
        ],
        "operationId": "legacyGetConnectionValidation",
        "summary": "Read connection validation state",
        "description": "Reads the validated/connected flags and last check time. Reading this resource has no provider or persistence side effects.",
        "security": [
          {
            "LegacyServerAccessToken": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/SellingPointId"
          },
          {
            "$ref": "#/components/parameters/ConnectionId"
          }
        ],
        "responses": {
          "200": {
            "description": "Current validation state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/ConnectionNotFound"
          }
        }
      },
      "post": {
        "tags": [
          "Validation"
        ],
        "operationId": "legacyRunConnectionValidation",
        "summary": "Run configured connection validation",
        "description": "Invokes the module's configured validation actions and stores the resulting status. This can contact the integration provider and write validation/event records. It does not create an order or send normal restaurant events. A module without visible connection status or a setup with incomplete configuration returns 422.",
        "security": [
          {
            "LegacyServerAccessToken": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/SellingPointId"
          },
          {
            "$ref": "#/components/parameters/ConnectionId"
          }
        ],
        "responses": {
          "200": {
            "description": "Validation completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/ConnectionNotFound"
          },
          "422": {
            "description": "Validation is unavailable, configuration is incomplete, or provider configuration validation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "LegacyServerAccessToken": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-server-access-token",
        "description": "API server access token. Keep it on a trusted server; do not expose it in browser code."
      }
    },
    "parameters": {
      "SellingPointId": {
        "name": "sellingPointId",
        "in": "path",
        "required": true,
        "description": "Numeric restaurant/selling-point ID.",
        "schema": {
          "type": "integer",
          "minimum": 1
        }
      },
      "ConnectionId": {
        "name": "connectionId",
        "in": "path",
        "required": true,
        "description": "Numeric module setup ID.",
        "schema": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing, inactive, expired, or unauthorized server access token.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "ConnectionNotFound": {
        "description": "Connection does not exist or is not owned by this developer at the requested restaurant.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "InvalidRestaurant": {
        "description": "Invalid numeric restaurant ID.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "InvalidConfiguration": {
        "description": "Invalid JSON, undeclared field, or unsupported configuration value.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "SuccessEnvelope": {
        "type": "object",
        "required": [
          "success",
          "data"
        ],
        "properties": {
          "success": {
            "const": true
          },
          "data": {
            "type": "object"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "success",
          "error"
        ],
        "properties": {
          "success": {
            "const": false
          },
          "error": {
            "type": "object",
            "required": [
              "code"
            ],
            "properties": {
              "code": {
                "type": "string"
              }
            }
          }
        }
      },
      "Connection": {
        "type": "object",
        "required": [
          "id",
          "restaurantId",
          "module",
          "status",
          "configured",
          "validated",
          "connected",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Module setup ID."
          },
          "restaurantId": {
            "type": "string"
          },
          "module": {
            "type": "object",
            "required": [
              "id",
              "code",
              "name"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "code": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "unknown",
              "configured"
            ]
          },
          "configured": {
            "type": "boolean"
          },
          "validated": {
            "type": "boolean"
          },
          "connected": {
            "type": "boolean"
          },
          "updatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "ConnectionListResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/SuccessEnvelope"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "type": "object",
                "required": [
                  "items",
                  "pagination"
                ],
                "properties": {
                  "items": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/Connection"
                    }
                  },
                  "pagination": {
                    "type": "object",
                    "required": [
                      "page",
                      "limit",
                      "total",
                      "totalPages"
                    ],
                    "properties": {
                      "page": {
                        "type": "integer"
                      },
                      "limit": {
                        "type": "integer"
                      },
                      "total": {
                        "type": "integer"
                      },
                      "totalPages": {
                        "type": "integer"
                      }
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "ConfigurationField": {
        "type": "object",
        "required": [
          "key",
          "label",
          "type",
          "required",
          "options",
          "secret",
          "configured",
          "value"
        ],
        "properties": {
          "key": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "required": {
            "type": "boolean"
          },
          "options": {
            "type": "array",
            "items": {}
          },
          "secret": {
            "type": "boolean"
          },
          "configured": {
            "type": "boolean"
          },
          "value": {
            "description": "Null for secret fields; otherwise the current non-secret value.",
            "type": [
              "string",
              "number",
              "boolean",
              "null"
            ]
          }
        }
      },
      "Configuration": {
        "type": "object",
        "required": [
          "connectionId",
          "restaurantId",
          "module",
          "providerClientId",
          "fields",
          "configured",
          "validated",
          "connected",
          "updatedAt"
        ],
        "properties": {
          "connectionId": {
            "type": "string"
          },
          "restaurantId": {
            "type": [
              "string",
              "null"
            ]
          },
          "module": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "code": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "providerClientId": {
            "type": [
              "string",
              "null"
            ]
          },
          "fields": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ConfigurationField"
            }
          },
          "configured": {
            "type": "boolean"
          },
          "validated": {
            "type": "boolean"
          },
          "connected": {
            "type": "boolean"
          },
          "updatedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "ConfigurationResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/SuccessEnvelope"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "type": "object",
                "required": [
                  "configuration"
                ],
                "properties": {
                  "configuration": {
                    "$ref": "#/components/schemas/Configuration"
                  }
                }
              }
            }
          }
        ]
      },
      "ConfigurationPatch": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "config": {
            "type": "object",
            "additionalProperties": {
              "type": [
                "string",
                "number",
                "boolean",
                "null"
              ]
            },
            "description": "Partial map of module-declared setting keys."
          },
          "providerClientId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 90
          }
        }
      },
      "Validation": {
        "type": "object",
        "required": [
          "validated",
          "connected",
          "checkedAt",
          "available"
        ],
        "properties": {
          "validated": {
            "type": "boolean"
          },
          "connected": {
            "type": "boolean"
          },
          "checkedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "available": {
            "type": "boolean"
          }
        }
      },
      "ValidationResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/SuccessEnvelope"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "type": "object",
                "required": [
                  "validation"
                ],
                "properties": {
                  "validation": {
                    "$ref": "#/components/schemas/Validation"
                  }
                }
              }
            }
          }
        ]
      }
    }
  }
}
