{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://wildflower.computer/schemas/sdk-model.schema.json",
  "title": "Wildflower SDK model",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "clientName",
    "defaultBaseUrl",
    "cli",
    "packages",
    "resources",
    "credentials",
    "providerCapabilities",
    "providerRuntimeCapabilities",
    "providerConnections",
    "operationExamples",
    "errorDocumentation",
    "languageOverrides"
  ],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "schemaVersion": {
      "const": 1
    },
    "clientName": {
      "type": "string",
      "minLength": 1
    },
    "defaultBaseUrl": {
      "type": "string",
      "format": "uri"
    },
    "cli": {
      "$ref": "#/$defs/cli"
    },
    "packages": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "typescript",
        "python",
        "rust",
        "go",
        "zig"
      ],
      "properties": {
        "typescript": {
          "$ref": "#/$defs/packageDocumentation"
        },
        "python": {
          "$ref": "#/$defs/packageDocumentation"
        },
        "rust": {
          "$ref": "#/$defs/packageDocumentation"
        },
        "go": {
          "$ref": "#/$defs/packageDocumentation"
        },
        "zig": {
          "$ref": "#/$defs/packageDocumentation"
        }
      }
    },
    "resources": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "operations"
        ],
        "properties": {
          "operations": {
            "type": "object",
            "minProperties": 1,
            "additionalProperties": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      }
    },
    "credentials": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "scheme",
          "scope"
        ],
        "properties": {
          "scheme": {
            "type": "string",
            "minLength": 1
          },
          "scope": {
            "enum": [
              "client",
              "request"
            ]
          },
          "rememberByResourceId": {
            "type": "boolean"
          }
        }
      }
    },
    "providerCapabilities": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "uniqueItems": true
      }
    },
    "providerRuntimeCapabilities": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "$ref": "#/$defs/providerRuntimeCapabilities"
      }
    },
    "providerConnections": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "array",
        "items": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "name",
            "header"
          ],
          "properties": {
            "name": {
              "type": "string",
              "pattern": "^[a-z][A-Za-z0-9]*$"
            },
            "header": {
              "type": "string",
              "pattern": "^[A-Za-z0-9-]+$"
            }
          }
        }
      }
    },
    "operationExamples": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "$ref": "#/$defs/operationExample"
      }
    },
    "errorDocumentation": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "$ref": "#/$defs/errorDocumentation"
      }
    },
    "languageOverrides": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "additionalProperties": {
          "type": "string"
        }
      }
    }
  },
  "$defs": {
    "cli": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "version",
        "binaryName",
        "aliases",
        "description",
        "commands",
        "workflows",
        "providerProfiles"
      ],
      "properties": {
        "version": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$"
        },
        "binaryName": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]*$"
        },
        "aliases": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]*$"
          }
        },
        "description": {
          "type": "string",
          "minLength": 1
        },
        "commands": {
          "type": "object",
          "minProperties": 1,
          "additionalProperties": {
            "type": "object",
            "minProperties": 1,
            "additionalProperties": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "workflows": {
          "type": "object",
          "minProperties": 1,
          "additionalProperties": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "providerProfiles": {
          "type": "object",
          "minProperties": 1,
          "additionalProperties": {
            "$ref": "#/$defs/cliProviderProfile"
          }
        }
      }
    },
    "cliProviderProfile": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "apiKeyEnvironment",
        "connectionEnvironment"
      ],
      "properties": {
        "apiKeyEnvironment": {
          "$ref": "#/$defs/environmentVariable"
        },
        "connectionEnvironment": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/environmentVariable"
          }
        }
      }
    },
    "environmentVariable": {
      "type": "string",
      "pattern": "^[A-Z][A-Z0-9_]*$"
    },
    "providerRuntimeCapabilities": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "imageMode",
        "timeoutMode",
        "supportsCwd",
        "supportsEnv",
        "outputStreams",
        "supportsPersistentResume",
        "supportsExplicitStop",
        "supportsSnapshots",
        "supportsRestore",
        "supportsDelete"
      ],
      "properties": {
        "imageMode": {
          "enum": [
            "template",
            "container",
            "blueprint",
            "fixed"
          ]
        },
        "timeoutMode": {
          "enum": [
            "seconds",
            "provider_managed"
          ]
        },
        "timeoutDefaultSeconds": {
          "type": "integer",
          "minimum": 1
        },
        "timeoutMaximumSeconds": {
          "type": "integer",
          "minimum": 1
        },
        "timeoutGranularitySeconds": {
          "type": "integer",
          "minimum": 1
        },
        "supportsCwd": {
          "type": "boolean"
        },
        "supportsEnv": {
          "type": "boolean"
        },
        "outputStreams": {
          "enum": [
            "separate",
            "combined"
          ]
        },
        "supportsPersistentResume": {
          "type": "boolean"
        },
        "supportsExplicitStop": {
          "type": "boolean"
        },
        "supportsSnapshots": {
          "type": "boolean"
        },
        "supportsRestore": {
          "type": "boolean"
        },
        "supportsDelete": {
          "type": "boolean"
        }
      }
    },
    "operationExample": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "pathParameters",
        "queryParameters",
        "response"
      ],
      "properties": {
        "pathParameters": {
          "type": "object",
          "additionalProperties": {
            "type": "string",
            "minLength": 1
          }
        },
        "queryParameters": {
          "type": "object",
          "additionalProperties": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              },
              {
                "type": "boolean"
              }
            ]
          }
        },
        "requestBody": true,
        "response": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "status",
            "body"
          ],
          "properties": {
            "status": {
              "type": "integer",
              "minimum": 200,
              "maximum": 299
            },
            "body": true
          }
        }
      }
    },
    "errorDocumentation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "description",
        "retryable",
        "remediation"
      ],
      "properties": {
        "description": {
          "type": "string",
          "minLength": 1
        },
        "retryable": {
          "type": "boolean"
        },
        "remediation": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "packageDocumentation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "displayName",
        "packageName",
        "description",
        "runtime",
        "asyncModel",
        "installCommand",
        "distributionStatus"
      ],
      "properties": {
        "displayName": {
          "type": "string",
          "minLength": 1
        },
        "packageName": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string",
          "minLength": 1
        },
        "runtime": {
          "type": "string",
          "minLength": 1
        },
        "asyncModel": {
          "type": "string",
          "minLength": 1
        },
        "installCommand": {
          "type": "string",
          "minLength": 1
        },
        "distributionStatus": {
          "enum": [
            "source-only",
            "published"
          ]
        }
      }
    }
  }
}
