{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:cede:schema:exchange-connector:v0",
  "title": "Craton model exchange connector, v0",
  "description": "The body of GET /internal/exchange/models/{id}/connector: what the model lab needs to run an exchange model for one account, the provider's credentials included. This route answers only Craton's own services, on the same machine, holding the deployment's internal credential; it refuses every request that arrives from anywhere else, and no other route returns credentials. It answers for a listed model the account may run (free, granted, or the provider's own), and for the provider's own model in any state, so a provider can try a model before asking for review.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "model_id",
    "version",
    "account_id",
    "basis",
    "kind",
    "base_url",
    "model_pk",
    "samples",
    "credentials"
  ],
  "properties": {
    "schema_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
    "model_id": { "type": "string", "pattern": "^xm_[0-9a-f]{16}$" },
    "version": { "type": "string", "minLength": 1, "description": "The listing's version at the moment of asking." },
    "account_id": { "type": "string", "pattern": "^acct_[0-9a-f]{24}$", "description": "The account the answer was given for." },
    "basis": {
      "enum": ["free", "granted", "provider"],
      "description": "Why the account may run the model: the listing is free, the provider granted the account, or the account is the provider."
    },
    "kind": { "const": "oasis-platform-v2" },
    "base_url": { "type": "string", "pattern": "^https://[^\\s?#@]+$" },
    "model_pk": { "type": "integer", "minimum": 1 },
    "samples": { "type": "integer", "minimum": 1, "maximum": 1000 },
    "oed": {
      "type": "object",
      "additionalProperties": false,
      "description": "Present when the listing names them: the OED country, occupancy and construction codes and the currency the model expects on each location. Each member is optional.",
      "properties": {
        "country_code": { "type": "string", "pattern": "^[A-Z]{2}$" },
        "occupancy_code": { "type": "integer", "minimum": 1 },
        "construction_code": { "type": "integer", "minimum": 1 },
        "currency": { "type": "string", "pattern": "^[A-Z]{3}$" }
      }
    },
    "credentials": {
      "description": "The platform login, decrypted: a user name and password for its access_token/ endpoint, or tokens.",
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["username", "password"],
          "properties": {
            "username": { "type": "string", "minLength": 1 },
            "password": { "type": "string", "minLength": 1 }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["access_token"],
          "properties": {
            "access_token": { "type": "string", "minLength": 1 },
            "refresh_token": { "type": "string", "minLength": 1 }
          }
        }
      ]
    }
  }
}
