{
  "openapi": "3.1.0",
  "info": {
    "title": "Layer8 Systems API",
    "version": "1.0.0",
    "description": "REST API for Layer8 Systems — programmatic access to assets, maps, and notes.\n\nAll endpoints require a valid Clerk JWT in the `Authorization: Bearer <token>` header unless noted otherwise.\n\nBase URL: `https://your-convex-deployment.convex.site`",
    "contact": {
      "email": "support@layer8systems.ca"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://outstanding-gecko-609.convex.site",
      "description": "Production"
    },
    {
      "url": "https://grandiose-civet-55.convex.site",
      "description": "Staging"
    }
  ],
  "components": {
    "securitySchemes": {
      "ClerkJWT": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Obtain a token from Clerk's `getToken()` SDK method."
      }
    },
    "schemas": {
      "Asset": {
        "type": "object",
        "required": ["_id", "name", "type", "status"],
        "properties": {
          "_id": { "type": "string", "description": "Convex document ID" },
          "_creationTime": { "type": "number", "description": "Unix timestamp (ms)" },
          "name": { "type": "string" },
          "type": { "type": "string", "example": "server" },
          "category": {
            "type": "string",
            "enum": ["hardware", "software", "cloud", "peripheral", "other"]
          },
          "status": {
            "type": "string",
            "enum": ["active", "inactive", "maintenance", "retired", "ordered"]
          },
          "manufacturer": { "type": "string" },
          "model": { "type": "string" },
          "serialNumber": { "type": "string" },
          "location": { "type": "string" },
          "rack": { "type": "string" },
          "rackUnit": { "type": "number" },
          "assignedTo": { "type": "string" },
          "warrantyExpiry": { "type": "number", "description": "Unix timestamp (ms)" },
          "notes": { "type": "string" },
          "tags": { "type": "array", "items": { "type": "string" } }
        }
      },
      "Map": {
        "type": "object",
        "required": ["_id", "name", "userId"],
        "properties": {
          "_id": { "type": "string" },
          "_creationTime": { "type": "number" },
          "name": { "type": "string" },
          "description": { "type": "string" },
          "isPublic": { "type": "boolean" },
          "nodeCount": { "type": "number" },
          "edgeCount": { "type": "number" },
          "tags": { "type": "array", "items": { "type": "string" } },
          "updatedAt": { "type": "number" }
        }
      },
      "NoteMeta": {
        "type": "object",
        "required": ["_id", "title", "type"],
        "properties": {
          "_id": { "type": "string" },
          "_creationTime": { "type": "number" },
          "title": { "type": "string" },
          "type": {
            "type": "string",
            "enum": ["note", "runbook", "config", "procedure", "reference"]
          },
          "isPinned": { "type": "boolean" },
          "tags": { "type": "array", "items": { "type": "string" } },
          "updatedAt": { "type": "number" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string" }
        }
      }
    }
  },
  "security": [{ "ClerkJWT": [] }],
  "paths": {
    "/api/v1/assets": {
      "get": {
        "summary": "List assets",
        "operationId": "listAssets",
        "tags": ["Assets"],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["active", "inactive", "maintenance", "retired", "ordered"]
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["hardware", "software", "cloud", "peripheral", "other"]
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": { "type": "string" }
          },
          {
            "name": "search",
            "in": "query",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Array of assets",
            "content": {
              "application/json": {
                "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Asset" } }
              }
            }
          },
          "401": { "description": "Unauthorized" },
          "429": { "description": "Rate limit exceeded" }
        }
      },
      "post": {
        "summary": "Create an asset",
        "operationId": "createAsset",
        "tags": ["Assets"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name", "type", "status"],
                "properties": {
                  "name": { "type": "string" },
                  "type": { "type": "string" },
                  "status": {
                    "type": "string",
                    "enum": ["active", "inactive", "maintenance", "retired", "ordered"]
                  },
                  "category": { "type": "string" },
                  "manufacturer": { "type": "string" },
                  "model": { "type": "string" },
                  "serialNumber": { "type": "string" },
                  "location": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": { "id": { "type": "string" } }
                }
              }
            }
          },
          "400": { "description": "Validation error" },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/api/v1/assets/{id}": {
      "get": {
        "summary": "Get an asset by ID",
        "operationId": "getAsset",
        "tags": ["Assets"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Asset",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/Asset" } }
            }
          },
          "404": { "description": "Not found" }
        }
      },
      "patch": {
        "summary": "Update an asset",
        "operationId": "updateAsset",
        "tags": ["Assets"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/Asset" } }
          }
        },
        "responses": {
          "200": { "description": "Updated" },
          "400": { "description": "Validation error" },
          "404": { "description": "Not found" }
        }
      },
      "delete": {
        "summary": "Delete an asset",
        "operationId": "deleteAsset",
        "tags": ["Assets"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Deleted" },
          "404": { "description": "Not found" }
        }
      }
    },
    "/api/v1/maps": {
      "get": {
        "summary": "List maps",
        "operationId": "listMaps",
        "tags": ["Maps"],
        "responses": {
          "200": {
            "description": "Array of maps",
            "content": {
              "application/json": {
                "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Map" } }
              }
            }
          },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/api/v1/maps/{id}": {
      "get": {
        "summary": "Get a map by ID",
        "operationId": "getMap",
        "tags": ["Maps"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Map",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/Map" } }
            }
          },
          "404": { "description": "Not found" }
        }
      }
    },
    "/api/v1/notes": {
      "get": {
        "summary": "List note metadata (content is never returned — it is encrypted client-side)",
        "operationId": "listNotes",
        "tags": ["Notes"],
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["note", "runbook", "config", "procedure", "reference"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Array of note metadata",
            "content": {
              "application/json": {
                "schema": { "type": "array", "items": { "$ref": "#/components/schemas/NoteMeta" } }
              }
            }
          },
          "401": { "description": "Unauthorized" }
        }
      }
    },
    "/api/v1/notes/{id}": {
      "get": {
        "summary": "Get note metadata by ID",
        "operationId": "getNote",
        "tags": ["Notes"],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Note metadata",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/NoteMeta" } }
            }
          },
          "404": { "description": "Not found" }
        }
      }
    },
    "/api/shared-note": {
      "get": {
        "summary": "Get a publicly shared note by token",
        "operationId": "getSharedNote",
        "tags": ["Notes"],
        "security": [],
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": { "type": "string" },
            "description": "The share token from the note's public share URL"
          }
        ],
        "responses": {
          "200": { "description": "Shared note metadata" },
          "404": { "description": "Share not found or expired" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    }
  }
}
