{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://developer.sianlabs.co.uk/specs/control-frontier/v1/workforce-dataset.schema.json",
  "type": "object",
  "properties": {
    "contractVersion": {
      "const": "sianlabs.workforce/1.0-draft"
    },
    "chunkIndex": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9999
    },
    "chunkSha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "world": {
      "$ref": "#/$defs/World"
    },
    "revisions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Revision"
      },
      "maxItems": 2000
    }
  },
  "required": [
    "contractVersion",
    "chunkIndex",
    "chunkSha256",
    "world",
    "revisions"
  ],
  "additionalProperties": false,
  "$defs": {
    "Jurisdiction": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 32
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        }
      },
      "required": [
        "id",
        "code",
        "name",
        "region"
      ],
      "additionalProperties": false
    },
    "LegalEntity": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "kind": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "jurisdictionId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "parentLegalEntityId": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            {
              "type": "null"
            }
          ]
        },
        "branchJurisdictionIds": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "maxItems": 250
        },
        "status": {
          "type": "string",
          "enum": [
            "active",
            "dormant"
          ]
        }
      },
      "required": [
        "id",
        "code",
        "name",
        "kind",
        "jurisdictionId",
        "parentLegalEntityId",
        "branchJurisdictionIds",
        "status"
      ],
      "additionalProperties": false
    },
    "Location": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "city": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "countryCode": {
          "type": "string",
          "pattern": "^[A-Z]{2}$"
        },
        "jurisdictionId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "siteType": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "timeZone": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        }
      },
      "required": [
        "id",
        "code",
        "name",
        "city",
        "countryCode",
        "jurisdictionId",
        "region",
        "siteType",
        "timeZone"
      ],
      "additionalProperties": false
    },
    "Team": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "unitType": {
          "type": "string",
          "enum": [
            "group",
            "division",
            "business_unit",
            "department",
            "sub_department",
            "team"
          ]
        },
        "jobFunction": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "divisionCode": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 64
            },
            {
              "type": "null"
            }
          ]
        },
        "parentTeamId": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            {
              "type": "null"
            }
          ]
        },
        "scope": {
          "type": "string",
          "enum": [
            "global",
            "regional",
            "local"
          ]
        },
        "region": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "primaryLocationId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "legalEntityId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "costCentre": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "headPersonId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "alignedDivisionCode": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 64
            },
            {
              "type": "null"
            }
          ]
        },
        "establishedOn": {
          "type": "string",
          "format": "date"
        }
      },
      "required": [
        "id",
        "name",
        "unitType",
        "jobFunction",
        "divisionCode",
        "parentTeamId",
        "scope",
        "region",
        "primaryLocationId",
        "legalEntityId",
        "costCentre",
        "headPersonId",
        "alignedDivisionCode",
        "establishedOn"
      ],
      "additionalProperties": false
    },
    "Person": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "workerId": {
          "type": "string",
          "pattern": "^[WC][0-9]{8}$"
        },
        "givenName": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "familyName": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "preferredGivenName": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            {
              "type": "null"
            }
          ]
        },
        "displayName": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "email": {
          "type": "string",
          "format": "email",
          "maxLength": 320
        },
        "employment": {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "permanent",
                "fixed_term",
                "contractor"
              ]
            },
            "status": {
              "type": "string",
              "enum": [
                "active",
                "on_leave",
                "pending_start",
                "terminated"
              ]
            },
            "hireDate": {
              "type": "string",
              "format": "date"
            },
            "endDate": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date"
                },
                {
                  "type": "null"
                }
              ]
            },
            "fte": {
              "type": "number",
              "exclusiveMinimum": 0,
              "maximum": 1
            }
          },
          "required": [
            "type",
            "status",
            "hireDate",
            "endDate",
            "fte"
          ],
          "additionalProperties": false
        },
        "job": {
          "type": "object",
          "properties": {
            "familyCode": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            },
            "jobFunction": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "title": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "corporateTitle": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "grade": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            },
            "seniority": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            },
            "role": {
              "type": "string",
              "enum": [
                "group_head",
                "unit_head",
                "team_lead",
                "staff",
                "individual_contributor"
              ]
            },
            "isPeopleManager": {
              "type": "boolean"
            }
          },
          "required": [
            "familyCode",
            "jobFunction",
            "title",
            "corporateTitle",
            "grade",
            "seniority",
            "role",
            "isPeopleManager"
          ],
          "additionalProperties": false
        },
        "primaryTeamId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "divisionCode": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 64
            },
            {
              "type": "null"
            }
          ]
        },
        "locationId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "legalEntityId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "managerId": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            {
              "type": "null"
            }
          ]
        },
        "directory": {
          "type": "object",
          "properties": {
            "objectId": {
              "type": "string",
              "format": "uuid"
            },
            "userPrincipalName": {
              "type": "string",
              "minLength": 1,
              "maxLength": 320
            },
            "mailNickname": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "samAccountName": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            }
          },
          "required": [
            "objectId",
            "userPrincipalName",
            "mailNickname",
            "samAccountName"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "id",
        "workerId",
        "givenName",
        "familyName",
        "preferredGivenName",
        "displayName",
        "email",
        "employment",
        "job",
        "primaryTeamId",
        "divisionCode",
        "locationId",
        "legalEntityId",
        "managerId",
        "directory"
      ],
      "additionalProperties": false
    },
    "TeamMembership": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "personId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "teamId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "kind": {
          "type": "string",
          "enum": [
            "primary",
            "matrix"
          ]
        },
        "role": {
          "type": "string",
          "enum": [
            "head",
            "lead",
            "member"
          ]
        },
        "validFrom": {
          "type": "string",
          "format": "date"
        },
        "validTo": {
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "personId",
        "teamId",
        "kind",
        "role",
        "validFrom",
        "validTo"
      ],
      "additionalProperties": false
    },
    "ReportingLine": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "personId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "managerId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "kind": {
          "type": "string",
          "enum": [
            "solid",
            "dotted"
          ]
        },
        "validFrom": {
          "type": "string",
          "format": "date"
        },
        "validTo": {
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "personId",
        "managerId",
        "kind",
        "validFrom",
        "validTo"
      ],
      "additionalProperties": false
    },
    "TeamParent": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "childTeamId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "parentTeamId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "validFrom": {
          "type": "string",
          "format": "date"
        },
        "validTo": {
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "childTeamId",
        "parentTeamId",
        "validFrom",
        "validTo"
      ],
      "additionalProperties": false
    },
    "DocumentedException": {
      "type": "object",
      "properties": {
        "rule": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "subjectId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "reason": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2000
        }
      },
      "required": [
        "rule",
        "subjectId",
        "reason"
      ],
      "additionalProperties": false
    },
    "World": {
      "type": "object",
      "properties": {
        "asOf": {
          "type": "string",
          "format": "date"
        },
        "jurisdictions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Jurisdiction"
          },
          "maxItems": 2000
        },
        "legalEntities": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/LegalEntity"
          },
          "maxItems": 2000
        },
        "locations": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Location"
          },
          "maxItems": 2000
        },
        "teams": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Team"
          },
          "maxItems": 2000
        },
        "people": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Person"
          },
          "maxItems": 2000
        },
        "memberships": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/TeamMembership"
          },
          "maxItems": 2000
        },
        "reportingLines": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ReportingLine"
          },
          "maxItems": 2000
        },
        "teamHierarchy": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/TeamParent"
          },
          "maxItems": 2000
        },
        "exceptions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/DocumentedException"
          },
          "maxItems": 2000
        }
      },
      "required": [
        "asOf",
        "jurisdictions",
        "legalEntities",
        "locations",
        "teams",
        "people",
        "memberships",
        "reportingLines",
        "teamHierarchy",
        "exceptions"
      ],
      "additionalProperties": false
    },
    "Manifest": {
      "type": "object",
      "properties": {
        "contract": {
          "const": "demoforge.workforce.manifest/1"
        },
        "generator": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "version": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            }
          },
          "required": [
            "name",
            "version"
          ],
          "additionalProperties": false
        },
        "profile": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "seed": {
          "oneOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            {
              "type": "object",
              "properties": {
                "sha256": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                }
              },
              "required": [
                "sha256"
              ],
              "additionalProperties": false
            }
          ]
        },
        "asOf": {
          "type": "string",
          "format": "date"
        },
        "configSchema": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "configVersion": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "configSha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "neutralContract": {
          "const": "demoforge.neutral.workforce/1.0"
        },
        "sourceContracts": {
          "type": "object",
          "additionalProperties": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          }
        },
        "quality": {
          "type": "string",
          "enum": [
            "clean",
            "realistic",
            "hostile"
          ]
        },
        "reference": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "version": {
                "type": "string",
                "minLength": 1,
                "maxLength": 80
              },
              "sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              }
            },
            "required": [
              "version",
              "sha256"
            ],
            "additionalProperties": false
          }
        },
        "counts": {
          "type": "object",
          "additionalProperties": {
            "type": "integer",
            "minimum": 0
          }
        },
        "validation": {
          "type": "object",
          "properties": {
            "passed": {
              "type": "boolean"
            },
            "hard": {
              "type": "integer",
              "minimum": 0
            },
            "soft": {
              "type": "integer",
              "minimum": 0
            }
          },
          "required": [
            "passed",
            "hard",
            "soft"
          ],
          "additionalProperties": false
        },
        "files": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "path": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500
              },
              "records": {
                "type": "integer",
                "minimum": 0
              },
              "bytes": {
                "type": "integer",
                "minimum": 0
              },
              "sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              }
            },
            "required": [
              "path",
              "records",
              "bytes",
              "sha256"
            ],
            "additionalProperties": false
          },
          "maxItems": 1000
        },
        "datasetSha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "required": [
        "contract",
        "generator",
        "profile",
        "seed",
        "asOf",
        "configSchema",
        "configVersion",
        "configSha256",
        "neutralContract",
        "sourceContracts",
        "quality",
        "reference",
        "counts",
        "validation",
        "files",
        "datasetSha256"
      ],
      "additionalProperties": false
    },
    "Revision": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "entity": {
              "const": "jurisdiction"
            },
            "sourceRecordId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "sourceRevisionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "revisionGroupId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "episodeId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "effectiveFrom": {
              "type": "string",
              "format": "date-time"
            },
            "effectiveTo": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ]
            },
            "supersedesSourceRevisionId": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 255
                },
                {
                  "type": "null"
                }
              ]
            },
            "operation": {
              "type": "string",
              "enum": [
                "observe",
                "correct",
                "close"
              ]
            },
            "record": {
              "$ref": "#/$defs/Jurisdiction"
            }
          },
          "required": [
            "entity",
            "sourceRecordId",
            "sourceRevisionId",
            "revisionGroupId",
            "episodeId",
            "effectiveFrom",
            "effectiveTo",
            "supersedesSourceRevisionId",
            "operation",
            "record"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "entity": {
              "const": "legal_entity"
            },
            "sourceRecordId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "sourceRevisionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "revisionGroupId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "episodeId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "effectiveFrom": {
              "type": "string",
              "format": "date-time"
            },
            "effectiveTo": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ]
            },
            "supersedesSourceRevisionId": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 255
                },
                {
                  "type": "null"
                }
              ]
            },
            "operation": {
              "type": "string",
              "enum": [
                "observe",
                "correct",
                "close"
              ]
            },
            "record": {
              "$ref": "#/$defs/LegalEntity"
            }
          },
          "required": [
            "entity",
            "sourceRecordId",
            "sourceRevisionId",
            "revisionGroupId",
            "episodeId",
            "effectiveFrom",
            "effectiveTo",
            "supersedesSourceRevisionId",
            "operation",
            "record"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "entity": {
              "const": "location"
            },
            "sourceRecordId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "sourceRevisionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "revisionGroupId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "episodeId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "effectiveFrom": {
              "type": "string",
              "format": "date-time"
            },
            "effectiveTo": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ]
            },
            "supersedesSourceRevisionId": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 255
                },
                {
                  "type": "null"
                }
              ]
            },
            "operation": {
              "type": "string",
              "enum": [
                "observe",
                "correct",
                "close"
              ]
            },
            "record": {
              "$ref": "#/$defs/Location"
            }
          },
          "required": [
            "entity",
            "sourceRecordId",
            "sourceRevisionId",
            "revisionGroupId",
            "episodeId",
            "effectiveFrom",
            "effectiveTo",
            "supersedesSourceRevisionId",
            "operation",
            "record"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "entity": {
              "const": "team"
            },
            "sourceRecordId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "sourceRevisionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "revisionGroupId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "episodeId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "effectiveFrom": {
              "type": "string",
              "format": "date-time"
            },
            "effectiveTo": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ]
            },
            "supersedesSourceRevisionId": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 255
                },
                {
                  "type": "null"
                }
              ]
            },
            "operation": {
              "type": "string",
              "enum": [
                "observe",
                "correct",
                "close"
              ]
            },
            "record": {
              "$ref": "#/$defs/Team"
            }
          },
          "required": [
            "entity",
            "sourceRecordId",
            "sourceRevisionId",
            "revisionGroupId",
            "episodeId",
            "effectiveFrom",
            "effectiveTo",
            "supersedesSourceRevisionId",
            "operation",
            "record"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "entity": {
              "const": "person"
            },
            "sourceRecordId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "sourceRevisionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "revisionGroupId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "episodeId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "effectiveFrom": {
              "type": "string",
              "format": "date-time"
            },
            "effectiveTo": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ]
            },
            "supersedesSourceRevisionId": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 255
                },
                {
                  "type": "null"
                }
              ]
            },
            "operation": {
              "type": "string",
              "enum": [
                "observe",
                "correct",
                "close"
              ]
            },
            "record": {
              "$ref": "#/$defs/Person"
            }
          },
          "required": [
            "entity",
            "sourceRecordId",
            "sourceRevisionId",
            "revisionGroupId",
            "episodeId",
            "effectiveFrom",
            "effectiveTo",
            "supersedesSourceRevisionId",
            "operation",
            "record"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "entity": {
              "const": "membership"
            },
            "sourceRecordId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "sourceRevisionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "revisionGroupId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "episodeId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "effectiveFrom": {
              "type": "string",
              "format": "date-time"
            },
            "effectiveTo": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ]
            },
            "supersedesSourceRevisionId": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 255
                },
                {
                  "type": "null"
                }
              ]
            },
            "operation": {
              "type": "string",
              "enum": [
                "observe",
                "correct",
                "close"
              ]
            },
            "record": {
              "$ref": "#/$defs/TeamMembership"
            }
          },
          "required": [
            "entity",
            "sourceRecordId",
            "sourceRevisionId",
            "revisionGroupId",
            "episodeId",
            "effectiveFrom",
            "effectiveTo",
            "supersedesSourceRevisionId",
            "operation",
            "record"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "entity": {
              "const": "reporting_line"
            },
            "sourceRecordId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "sourceRevisionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "revisionGroupId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "episodeId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "effectiveFrom": {
              "type": "string",
              "format": "date-time"
            },
            "effectiveTo": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ]
            },
            "supersedesSourceRevisionId": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 255
                },
                {
                  "type": "null"
                }
              ]
            },
            "operation": {
              "type": "string",
              "enum": [
                "observe",
                "correct",
                "close"
              ]
            },
            "record": {
              "$ref": "#/$defs/ReportingLine"
            }
          },
          "required": [
            "entity",
            "sourceRecordId",
            "sourceRevisionId",
            "revisionGroupId",
            "episodeId",
            "effectiveFrom",
            "effectiveTo",
            "supersedesSourceRevisionId",
            "operation",
            "record"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "entity": {
              "const": "team_parent"
            },
            "sourceRecordId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "sourceRevisionId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "revisionGroupId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "episodeId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "effectiveFrom": {
              "type": "string",
              "format": "date-time"
            },
            "effectiveTo": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ]
            },
            "supersedesSourceRevisionId": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 255
                },
                {
                  "type": "null"
                }
              ]
            },
            "operation": {
              "type": "string",
              "enum": [
                "observe",
                "correct",
                "close"
              ]
            },
            "record": {
              "$ref": "#/$defs/TeamParent"
            }
          },
          "required": [
            "entity",
            "sourceRecordId",
            "sourceRevisionId",
            "revisionGroupId",
            "episodeId",
            "effectiveFrom",
            "effectiveTo",
            "supersedesSourceRevisionId",
            "operation",
            "record"
          ],
          "additionalProperties": false
        }
      ]
    },
    "WorkforceChunk": {
      "type": "object",
      "properties": {
        "contractVersion": {
          "const": "sianlabs.workforce/1.0-draft"
        },
        "chunkIndex": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9999
        },
        "chunkSha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "world": {
          "$ref": "#/$defs/World"
        },
        "revisions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Revision"
          },
          "maxItems": 2000
        }
      },
      "required": [
        "contractVersion",
        "chunkIndex",
        "chunkSha256",
        "world",
        "revisions"
      ],
      "additionalProperties": false
    },
    "DatasetCreate": {
      "type": "object",
      "properties": {
        "contractVersion": {
          "const": "sianlabs.workforce/1.0-draft"
        },
        "manifest": {
          "$ref": "#/$defs/Manifest"
        },
        "expectedChunks": {
          "type": "integer",
          "minimum": 1,
          "maximum": 10000
        },
        "expectedItems": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000
        },
        "mode": {
          "type": "string",
          "enum": [
            "snapshot",
            "incremental"
          ]
        },
        "snapshotEffectiveFrom": {
          "type": "string",
          "format": "date-time"
        }
      },
      "required": [
        "contractVersion",
        "manifest",
        "expectedChunks",
        "expectedItems",
        "mode",
        "snapshotEffectiveFrom"
      ],
      "additionalProperties": false
    },
    "Receipt": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "state": {
          "type": "string",
          "enum": [
            "collecting",
            "ready",
            "queued"
          ]
        },
        "requestId": {
          "type": "string",
          "format": "uuid"
        }
      },
      "required": [
        "id",
        "state",
        "requestId"
      ],
      "additionalProperties": false
    },
    "Counts": {
      "type": "object",
      "properties": {
        "created": {
          "type": "integer",
          "minimum": 0
        },
        "updated": {
          "type": "integer",
          "minimum": 0
        },
        "unchanged": {
          "type": "integer",
          "minimum": 0
        },
        "conflicted": {
          "type": "integer",
          "minimum": 0
        },
        "rejected": {
          "type": "integer",
          "minimum": 0
        },
        "proposed": {
          "type": "integer",
          "minimum": 0
        },
        "accepted": {
          "type": "integer",
          "minimum": 0
        },
        "applied": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "created",
        "updated",
        "unchanged",
        "conflicted",
        "rejected",
        "proposed",
        "accepted",
        "applied"
      ],
      "additionalProperties": false
    },
    "Job": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "datasetId": {
          "type": "string",
          "format": "uuid"
        },
        "execution": {
          "type": "string",
          "enum": [
            "queued",
            "running",
            "completed",
            "partial",
            "failed"
          ]
        },
        "governance": {
          "type": "string",
          "enum": [
            "not_ready",
            "pending_review",
            "partially_approved",
            "approved",
            "rejected"
          ]
        },
        "application": {
          "type": "string",
          "enum": [
            "not_started",
            "running",
            "partial",
            "completed",
            "failed"
          ]
        },
        "counts": {
          "$ref": "#/$defs/Counts"
        },
        "requestId": {
          "type": "string",
          "format": "uuid"
        }
      },
      "required": [
        "id",
        "datasetId",
        "execution",
        "governance",
        "application",
        "counts",
        "requestId"
      ],
      "additionalProperties": false
    },
    "Item": {
      "type": "object",
      "properties": {
        "ordinal": {
          "type": "integer",
          "minimum": 0
        },
        "sourceRecordId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "sourceRevisionId": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            {
              "type": "null"
            }
          ]
        },
        "entity": {
          "type": "string",
          "enum": [
            "jurisdiction",
            "legal_entity",
            "location",
            "team",
            "person",
            "membership",
            "reporting_line",
            "team_parent"
          ]
        },
        "outcome": {
          "type": "string",
          "enum": [
            "created",
            "updated",
            "unchanged",
            "conflicted",
            "rejected"
          ]
        },
        "proposalId": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ]
        },
        "canonicalId": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ]
        },
        "proposalState": {
          "type": "string",
          "enum": [
            "none",
            "pending",
            "approved",
            "accepted",
            "rejected",
            "applied"
          ]
        },
        "code": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            {
              "type": "null"
            }
          ]
        },
        "field": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "ordinal",
        "sourceRecordId",
        "sourceRevisionId",
        "entity",
        "outcome",
        "proposalId",
        "canonicalId",
        "proposalState",
        "code",
        "field"
      ],
      "additionalProperties": false
    },
    "ItemPage": {
      "type": "object",
      "properties": {
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Item"
          },
          "maxItems": 500
        },
        "nextCursor": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 2000
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "items",
        "nextCursor"
      ],
      "additionalProperties": false
    },
    "Preview": {
      "type": "object",
      "properties": {
        "datasetId": {
          "type": "string",
          "format": "uuid"
        },
        "validationId": {
          "type": "string",
          "format": "uuid"
        },
        "valid": {
          "type": "boolean"
        },
        "counts": {
          "$ref": "#/$defs/Counts"
        },
        "requiresHumanReview": {
          "const": true
        },
        "errors": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "sourceRecordId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 255
              },
              "field": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "code": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100
              }
            },
            "required": [
              "sourceRecordId",
              "field",
              "code"
            ],
            "additionalProperties": false
          },
          "maxItems": 500
        }
      },
      "required": [
        "datasetId",
        "validationId",
        "valid",
        "counts",
        "requiresHumanReview",
        "errors"
      ],
      "additionalProperties": false
    },
    "Summary": {
      "type": "object",
      "properties": {
        "datasetId": {
          "type": "string",
          "format": "uuid"
        },
        "completeSourceSnapshot": {
          "type": "boolean"
        },
        "expectedItems": {
          "type": "integer",
          "minimum": 0
        },
        "receivedItems": {
          "type": "integer",
          "minimum": 0
        },
        "counts": {
          "$ref": "#/$defs/Counts"
        },
        "governance": {
          "type": "string",
          "enum": [
            "not_ready",
            "pending_review",
            "partially_approved",
            "approved",
            "rejected"
          ]
        },
        "application": {
          "type": "string",
          "enum": [
            "not_started",
            "running",
            "partial",
            "completed",
            "failed"
          ]
        }
      },
      "required": [
        "datasetId",
        "completeSourceSnapshot",
        "expectedItems",
        "receivedItems",
        "counts",
        "governance",
        "application"
      ],
      "additionalProperties": false
    },
    "Error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "enum": [
            "invalid_request",
            "unauthenticated",
            "forbidden",
            "not_found",
            "conflict",
            "payload_too_large",
            "unsupported_media_type",
            "validation_failed",
            "rate_limited",
            "unavailable"
          ]
        },
        "message": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "requestId": {
          "type": "string",
          "format": "uuid"
        },
        "retryable": {
          "type": "boolean"
        },
        "details": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "field": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "code": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100
              }
            },
            "required": [
              "field",
              "code"
            ],
            "additionalProperties": false
          },
          "maxItems": 100
        }
      },
      "required": [
        "code",
        "message",
        "requestId",
        "retryable",
        "details"
      ],
      "additionalProperties": false
    },
    "Capabilities": {
      "type": "object",
      "properties": {
        "apiVersion": {
          "const": "v1"
        },
        "contractVersion": {
          "const": "sianlabs.workforce/1.0-draft"
        },
        "status": {
          "const": "proposed"
        },
        "maxChunkItems": {
          "const": 2000
        },
        "maxChunkBytes": {
          "const": 10485760
        },
        "maxPageSize": {
          "const": 500
        },
        "scopes": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "maxItems": 20
        }
      },
      "required": [
        "apiVersion",
        "contractVersion",
        "status",
        "maxChunkItems",
        "maxChunkBytes",
        "maxPageSize",
        "scopes"
      ],
      "additionalProperties": false
    },
    "SchemaIndex": {
      "type": "object",
      "properties": {
        "contractVersion": {
          "const": "sianlabs.workforce/1.0-draft"
        },
        "schemaUrl": {
          "type": "string",
          "format": "uri-reference"
        },
        "sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "required": [
        "contractVersion",
        "schemaUrl",
        "sha256"
      ],
      "additionalProperties": false
    },
    "CanonicalPage": {
      "type": "object",
      "properties": {
        "items": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "canonicalId": {
                "type": "string",
                "format": "uuid"
              },
              "entity": {
                "type": "string",
                "enum": [
                  "jurisdiction",
                  "legal_entity",
                  "location",
                  "team",
                  "person",
                  "membership",
                  "reporting_line",
                  "team_parent"
                ]
              },
              "sourceRecordId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 255
              },
              "revisionId": {
                "type": "string",
                "format": "uuid"
              },
              "effectiveFrom": {
                "type": "string",
                "format": "date-time"
              },
              "effectiveTo": {
                "anyOf": [
                  {
                    "type": "string",
                    "format": "date-time"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "recordedAt": {
                "type": "string",
                "format": "date-time"
              },
              "record": {
                "oneOf": [
                  {
                    "$ref": "#/$defs/Jurisdiction"
                  },
                  {
                    "$ref": "#/$defs/LegalEntity"
                  },
                  {
                    "$ref": "#/$defs/Location"
                  },
                  {
                    "$ref": "#/$defs/Team"
                  },
                  {
                    "$ref": "#/$defs/Person"
                  },
                  {
                    "$ref": "#/$defs/TeamMembership"
                  },
                  {
                    "$ref": "#/$defs/ReportingLine"
                  },
                  {
                    "$ref": "#/$defs/TeamParent"
                  }
                ]
              }
            },
            "required": [
              "canonicalId",
              "entity",
              "sourceRecordId",
              "revisionId",
              "effectiveFrom",
              "effectiveTo",
              "recordedAt",
              "record"
            ],
            "additionalProperties": false
          },
          "maxItems": 500
        },
        "nextCursor": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 2000
            },
            {
              "type": "null"
            }
          ]
        },
        "at": {
          "type": "string",
          "format": "date-time"
        },
        "knownAt": {
          "type": "string",
          "format": "date-time"
        }
      },
      "required": [
        "items",
        "nextCursor",
        "at",
        "knownAt"
      ],
      "additionalProperties": false
    }
  }
}
