{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thesoftwarelens.com/saacip/0.1/schemas/terms.schema.json",
  "$comment": "SaaCIP 0.1 (https://thesoftwarelens.com/saacip/). Licensed under the Apache License 2.0.",
  "title": "SaaCIP 0.1 terms of the hire",
  "description": "The scope the hirer agrees to for one hire (section 7.2). The terms are the authoritative statement of the hire's kind and limits.",
  "type": "object",
  "required": [
    "protocol",
    "profile",
    "kind",
    "term",
    "autonomy_ceiling",
    "dry_run",
    "data_leaving",
    "model",
    "public_key",
    "environment"
  ],
  "properties": {
    "protocol": {
      "$ref": "common.schema.json#/$defs/protocol"
    },
    "profile": {
      "$ref": "common.schema.json#/$defs/profile"
    },
    "kind": {
      "$ref": "common.schema.json#/$defs/hireKind"
    },
    "term": {
      "description": "null for a standing hire; {days} for a trial; {window_seconds} for a task.",
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "required": [
            "days"
          ],
          "properties": {
            "days": {
              "type": "integer",
              "minimum": 1
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "window_seconds"
          ],
          "properties": {
            "window_seconds": {
              "type": "integer",
              "minimum": 1
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "autonomy_ceiling": {
      "$ref": "common.schema.json#/$defs/autonomyLevel"
    },
    "dry_run": {
      "type": "boolean"
    },
    "connectors": {
      "type": "array",
      "items": {
        "$ref": "connector-manifest.schema.json"
      },
      "description": "Resident profile: the connectors the capability found, one manifest each."
    },
    "data_leaving": {
      "type": "string",
      "description": "In plain words, what leaves the hirer's environment and where it goes."
    },
    "model": {
      "type": "string",
      "description": "The model the capability uses, or offline."
    },
    "public_key": {
      "$ref": "common.schema.json#/$defs/base64"
    },
    "environment": {
      "type": "string"
    },
    "ext": {
      "$ref": "common.schema.json#/$defs/ext"
    },
    "crit": {
      "$ref": "common.schema.json#/$defs/crit"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "kind": {
            "const": "standing"
          }
        }
      },
      "then": {
        "properties": {
          "term": {
            "type": "null"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "trial"
          }
        }
      },
      "then": {
        "properties": {
          "term": {
            "type": "object",
            "required": [
              "days"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "task"
          }
        }
      },
      "then": {
        "properties": {
          "term": {
            "type": "object",
            "required": [
              "window_seconds"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "profile": {
            "const": "resident"
          }
        }
      },
      "then": {
        "required": [
          "connectors"
        ]
      }
    }
  ]
}
