{
  "openapi": "3.0.1",
  "servers": [{ "url": "https://apis.<domain>" }],
  "info": {
    "title": "Connhex Provision service",
    "description": "HTTP API for Provision service",
    "version": "1.5.0"
  },
  "paths": {
    "/iot/provision/things": {
      "post": {
        "summary": "Provision a new thing",
        "description": "Provision a new things\n\nRequired Permission:\n\n - Resource: ```core:provision:things```\n\n - Action: ```core:provision:things```",
        "tags": ["Provision"],
        "requestBody": { "$ref": "#/components/requestBodies/ProvisionReq" },
        "responses": {
          "201": { "$ref": "#/components/responses/ProvisionRes" },
          "400": { "description": "Failed due to malformed JSON." },
          "401": {
            "description": "Missing or invalid access token provided."
          },
          "500": { "$ref": "#/components/responses/ServiceError" }
        }
      }
    },
    "/iot/provision/things/bulk": {
      "post": {
        "summary": "Bulk provision things",
        "description": "Provisions multiple things in a single request.\n\nRequired Permission:\n\n - Resource: ```core:provision:things```\n\n - Action: ```core:provision:things```",
        "tags": ["Provision"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ProvisionData"
                }
              }
            }
          }
        },
        "responses": {
          "200": { "$ref": "#/components/responses/BulkProvisionRes" },
          "400": { "description": "Failed due to malformed JSON." },
          "401": {
            "description": "Missing or invalid access token provided."
          },
          "500": { "$ref": "#/components/responses/ServiceError" }
        }
      },
      "delete": {
        "summary": "Bulk unprovision things",
        "description": "Remove multiple things by ID.\n\nRequired Permission:\n\n - Resource: ```core:unprovision:things```\n\n - Action: ```core:unprovision:things```",
        "tags": ["Provision"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "type": "array", "items": { "type": "string" } }
            }
          }
        },
        "responses": {
          "204": {
            "description": "No Content - things removed successfully"
          },
          "400": { "description": "Malformed request body" },
          "401": { "description": "Unauthorized" },
          "500": { "$ref": "#/components/responses/ServiceError" }
        }
      }
    },
    "/iot/provision/things/{id}": {
      "delete": {
        "summary": "Unprovision a thing",
        "description": "Remove a single thing by ID.\n\nRequired Permission:\n\n - Resource: ```core:things:{id}```\n\n - Action: ```core:unprovision:things```",
        "tags": ["Provision"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "204": {
            "description": "No Content - thing removed successfully"
          },
          "400": { "description": "Malformed request body" },
          "401": { "description": "Unauthorized" },
          "500": { "$ref": "#/components/responses/ServiceError" }
        }
      }
    }
  },
  "components": {
    "requestBodies": {
      "ProvisionReq": {
        "description": "Provision thing request body",
        "required": true,
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ProvisionData" }
          }
        }
      }
    },
    "schemas": {
      "ProvisionData": {
        "type": "object",
        "required": ["init_id", "init_key", "tenant", "model"],
        "properties": {
          "name": { "type": "string" },
          "tenant": { "type": "string" },
          "model": { "type": "string" },
          "init_id": {
            "type": "string",
            "description": "External identifier (MAC address or similar)"
          },
          "init_key": { "type": "string", "description": "External key" },
          "migration_key": { "type": "string" },
          "migration_key_quota": { "type": "integer", "format": "int32" }
        }
      },
      "Thing": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "key": { "type": "string" },
          "metadata": { "type": "object", "additionalProperties": true },
          "tenant": { "type": "string" },
          "model": { "type": "string" }
        }
      },
      "Channel": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "metadata": { "type": "object", "additionalProperties": true },
          "tenant": { "type": "string" }
        }
      },
      "ProvisionRes": {
        "type": "object",
        "properties": {
          "things": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Thing" }
          },
          "channels": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Channel" }
          },
          "client_cert": {
            "type": "object",
            "additionalProperties": { "type": "string" }
          },
          "client_key": {
            "type": "object",
            "additionalProperties": { "type": "string" }
          },
          "ca_cert": { "type": "string" },
          "ca_chain": { "type": "string" },
          "whitelisted": {
            "type": "object",
            "additionalProperties": { "type": "boolean" }
          },
          "error": { "type": "string" }
        }
      },
      "BulkResult": {
        "type": "object",
        "properties": {
          "things": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Thing" }
          },
          "processed": { "type": "integer" },
          "failed": { "type": "integer" },
          "errors": { "type": "array", "items": { "type": "string" } }
        }
      }
    },
    "responses": {
      "ServiceError": {
        "description": "Unexpected server-side error occurred."
      },
      "ProvisionRes": {
        "description": "Provisioning response data.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ProvisionRes" }
          }
        }
      },
      "BulkProvisionRes": {
        "description": "Bulk provision response.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/BulkResult" }
          }
        }
      }
    },
    "securitySchemes": {
      "$ref": "../../../common.json#/components/securitySchemes"
    }
  },
  "security": [{ "chx_auth_session": [] }, { "bearer": [] }]
}
