{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://capp.local/schemas/capp.data-contract.v2.schema.json",
  "title": "cApp local-first data contract v2",
  "type": "object",
  "required": [
    "protocol",
    "collections"
  ],
  "properties": {
    "protocol": {
      "const": "capp.data-contract.v2"
    },
    "namespace": {
      "type": "string"
    },
    "collections": {
      "oneOf": [
        {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "description": {
                "type": "string"
              },
              "keyField": {
                "type": "string",
                "minLength": 1
              },
              "schema": {
                "type": "object"
              },
              "capabilities": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "sync": {
                "type": "object",
                "properties": {
                  "mode": {
                    "enum": [
                      "none",
                      "push",
                      "pull",
                      "local-first",
                      "bidirectional"
                    ]
                  },
                  "pushRoute": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "pushMethod": {
                    "type": "string"
                  },
                  "pullRoute": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "pullMethod": {
                    "type": "string"
                  },
                  "cursorParam": {
                    "type": "string"
                  },
                  "ackRequired": {
                    "type": "boolean"
                  },
                  "conflict": {
                    "enum": [
                      "reject",
                      "local-wins",
                      "remote-wins"
                    ]
                  }
                },
                "additionalProperties": true
              },
              "revisions": {
                "type": "object",
                "properties": {
                  "enabled": {
                    "type": "boolean"
                  },
                  "authority": {
                    "enum": [
                      "server",
                      "local",
                      "hybrid"
                    ]
                  },
                  "monotonic": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": true
              },
              "tombstones": {
                "oneOf": [
                  {
                    "type": "boolean"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "enabled": {
                        "type": "boolean"
                      },
                      "retainUntilAcknowledged": {
                        "type": "boolean"
                      }
                    },
                    "additionalProperties": true
                  }
                ]
              },
              "metadata": {
                "type": "object"
              }
            },
            "additionalProperties": true
          }
        },
        {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "required": [
              "id"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "description": {
                "type": "string"
              },
              "keyField": {
                "type": "string",
                "minLength": 1
              },
              "schema": {
                "type": "object"
              },
              "capabilities": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "sync": {
                "type": "object",
                "properties": {
                  "mode": {
                    "enum": [
                      "none",
                      "push",
                      "pull",
                      "local-first",
                      "bidirectional"
                    ]
                  },
                  "pushRoute": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "pushMethod": {
                    "type": "string"
                  },
                  "pullRoute": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "pullMethod": {
                    "type": "string"
                  },
                  "cursorParam": {
                    "type": "string"
                  },
                  "ackRequired": {
                    "type": "boolean"
                  },
                  "conflict": {
                    "enum": [
                      "reject",
                      "local-wins",
                      "remote-wins"
                    ]
                  }
                },
                "additionalProperties": true
              },
              "revisions": {
                "type": "object",
                "properties": {
                  "enabled": {
                    "type": "boolean"
                  },
                  "authority": {
                    "enum": [
                      "server",
                      "local",
                      "hybrid"
                    ]
                  },
                  "monotonic": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": true
              },
              "tombstones": {
                "oneOf": [
                  {
                    "type": "boolean"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "enabled": {
                        "type": "boolean"
                      },
                      "retainUntilAcknowledged": {
                        "type": "boolean"
                      }
                    },
                    "additionalProperties": true
                  }
                ]
              },
              "metadata": {
                "type": "object"
              }
            },
            "additionalProperties": true
          }
        }
      ]
    },
    "localFirst": {
      "type": "object"
    },
    "metadata": {
      "type": "object"
    }
  },
  "additionalProperties": true
}
