{
  "openapi": "3.1.0",
  "info": {
    "title": "BLYSTON Connect Client & Provisioning API",
    "description": "Zero-trust client authentication, cryptographic license minting, capacity tracking, and binary distribution endpoints for BLYSTON Connect.",
    "version": "1.1.0",
    "contact": {
      "name": "BLYSTON Statutory Engineering",
      "email": "connect@blyston.online",
      "url": "https://connect.blyston.online"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://connect.blyston.online/#/how-it-works"
    }
  },
  "servers": [
    {
      "url": "https://connect.blyston.online",
      "description": "Production Edge (Johannesburg / Gaborone)"
    }
  ],
  "paths": {
    "/api/auth.php": {
      "post": {
        "summary": "Authenticate or Register Client Workstation Account",
        "description": "Handles client portal registration and session token issuance.",
        "operationId": "authenticateUser",
        "parameters": [
          {
            "name": "action",
            "in": "query",
            "required": true,
            "description": "Action type: 'login' or 'register'.",
            "schema": {
              "type": "string",
              "enum": ["login", "register"]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email", "password"],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "example": "auditor@enterprise.co.bw"
                  },
                  "password": {
                    "type": "string",
                    "format": "password",
                    "example": "P@ssw0rd2026!"
                  },
                  "company": {
                    "type": "string",
                    "example": "Kalahari Energy Ltd"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Authentication successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "user": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string", "example": "usr_9b3f2a1c" },
                        "email": { "type": "string", "example": "auditor@enterprise.co.bw" },
                        "company": { "type": "string", "example": "Kalahari Energy Ltd" },
                        "role": { "type": "string", "example": "CLIENT" }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid credentials",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": false },
                    "error": { "type": "string", "example": "Invalid email or password." }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/client.php": {
      "get": {
        "summary": "Retrieve Client Workstation Licenses & Status",
        "description": "Returns list of purchased software licenses, workstation pairings, and capacity ceilings.",
        "operationId": "getLicenses",
        "parameters": [
          {
            "name": "action",
            "in": "query",
            "required": true,
            "description": "Action type: 'licenses' or 'download_license'.",
            "schema": {
              "type": "string",
              "enum": ["licenses", "download_license"]
            }
          },
          {
            "name": "license_id",
            "in": "query",
            "required": false,
            "description": "License ID required when action is 'download_license'.",
            "schema": {
              "type": "string",
              "example": "lic_99a8b7c6"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Active license registry payload or armored license file stream",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "licenses": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": { "type": "string", "example": "lic_99a8b7c6" },
                          "tier": { "type": "string", "example": "CORE" },
                          "status": { "type": "string", "example": "ACTIVE" },
                          "max_rows": { "type": "integer", "example": 500000 },
                          "max_nodes": { "type": "integer", "example": 3 },
                          "nodes_paired": { "type": "integer", "example": 1 },
                          "expiry_date": { "type": "string", "example": "2027-10-11T00:00:00Z" }
                        }
                      }
                    }
                  }
                }
              },
              "text/plain": {
                "schema": {
                  "type": "string",
                  "example": "-----BEGIN BLYSTON LICENSE KEY-----\neyJhb...==\n-----END BLYSTON LICENSE KEY-----"
                }
              }
            }
          },
          "401": { "description": "Unauthorized session" }
        }
      },
      "post": {
        "summary": "Claim & Pair Workstation Hardware ID",
        "description": "Binds a client's local workstation Hardware ID (BLYS-XXXX-XXXX-XXXX) to an active software license.",
        "operationId": "claimHardwareId",
        "parameters": [
          {
            "name": "action",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["claim_hwid"]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["license_id", "hwid"],
                "properties": {
                  "license_id": { "type": "string", "example": "lic_99a8b7c6" },
                  "hwid": { "type": "string", "pattern": "^BLYS-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$", "example": "BLYS-B3A2-AE1C-09F5" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Hardware ID successfully claimed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "message": { "type": "string", "example": "Workstation paired successfully." }
                  }
                }
              }
            }
          },
          "400": { "description": "Maximum node allowance reached or invalid hardware ID format" }
        }
      }
    },
    "/api/download_engine.php": {
      "get": {
        "summary": "Zero-Trust Authenticated Desktop Binary Download Proxy",
        "description": "Streams cryptographically signed native desktop installer packages from the private storage edge without exposing backend credentials.",
        "operationId": "downloadBinary",
        "parameters": [
          {
            "name": "os",
            "in": "query",
            "required": true,
            "description": "Target client operating system: 'deb' (Debian/Ubuntu), 'appimage' (Universal Linux), or 'win' (Windows x64).",
            "schema": {
              "type": "string",
              "enum": ["deb", "appimage", "win", "windows", "linux"]
            }
          },
          {
            "name": "v",
            "in": "query",
            "required": false,
            "description": "Requested release version (defaults to latest GA '1.1.0').",
            "schema": {
              "type": "string",
              "default": "1.1.0",
              "enum": ["1.1.0", "1.0.0"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Native binary application stream",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "403": {
            "description": "Access denied: active license or pending workstation claim required"
          }
        }
      }
    },
    "/api/capture_payment.php": {
      "post": {
        "summary": "Capture One-Off PayPal Payment (SME Audit Pass)",
        "description": "Verifies and captures PayPal one-off payment for the 90-day SME Audit Pass (BWP 1,850).",
        "operationId": "captureOneOffPayment",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["orderID", "tier"],
                "properties": {
                  "orderID": { "type": "string", "example": "9XY12345AB678901C" },
                  "tier": { "type": "string", "enum": ["audit_pass"], "example": "audit_pass" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment captured and license issued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "license_id": { "type": "string", "example": "lic_audit_pass_882a" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/capture_subscription.php": {
      "post": {
        "summary": "Capture Recurring PayPal Subscription (Growth / Core)",
        "description": "Activates a recurring subscription agreement and provisions commercial workstation licenses.",
        "operationId": "captureSubscription",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["subscriptionID", "tier", "cycle"],
                "properties": {
                  "subscriptionID": { "type": "string", "example": "I-BW7890123XYZ" },
                  "tier": { "type": "string", "enum": ["growth", "core"], "example": "growth" },
                  "cycle": { "type": "string", "enum": ["monthly", "annual"], "example": "annual" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Subscription activated and license generated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "license_id": { "type": "string", "example": "lic_growth_annual_912f" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/community.php": {
      "get": {
        "summary": "Fetch Community Discussion Topics & Feature Requests",
        "operationId": "getCommunityTopics",
        "parameters": [
          {
            "name": "action",
            "in": "query",
            "required": true,
            "schema": { "type": "string", "enum": ["topics"] }
          }
        ],
        "responses": {
          "200": {
            "description": "List of active feature requests and statutory discussions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "topics": { "type": "array", "items": { "type": "object" } }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
