{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "contract_version",
    "record_id",
    "revision",
    "fictional",
    "review",
    "identities",
    "organization",
    "assignee",
    "assets",
    "evidence",
    "external_requests",
    "notes"
  ],
  "properties": {
    "schema_version": {
      "const": "maestro.linkedin-business-manager.record.v2"
    },
    "contract_version": {
      "const": "2.0.0"
    },
    "record_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "revision": {
      "type": "integer",
      "minimum": 1
    },
    "fictional": {
      "type": "boolean"
    },
    "review": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "reviewed_at",
        "max_evidence_age_days"
      ],
      "properties": {
        "reviewed_at": {
          "type": "string",
          "format": "date-time",
          "pattern": "Z$"
        },
        "max_evidence_age_days": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "identities": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "identity_id",
          "name",
          "type",
          "organization_id",
          "authorized_approver",
          "verification_evidence_id",
          "trust_root"
        ],
        "properties": {
          "identity_id": {
            "type": "string",
            "pattern": "^(person|org|bm):[a-z0-9][a-z0-9.-]{2,}$"
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "type": {
            "enum": [
              "PERSON",
              "ORGANIZATION",
              "BUSINESS_MANAGER"
            ]
          },
          "organization_id": {
            "type": "string",
            "minLength": 1
          },
          "authorized_approver": {
            "type": "boolean"
          },
          "verification_evidence_id": {
            "type": "string",
            "minLength": 1
          },
          "trust_root": {
            "type": "boolean"
          }
        }
      }
    },
    "organization": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "business_manager_name",
        "business_manager_id",
        "controlling_organization_id",
        "ownership_evidence_id",
        "ownership_event_at"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "business_manager_name": {
          "type": "string",
          "minLength": 1
        },
        "business_manager_id": {
          "type": "string",
          "minLength": 1
        },
        "controlling_organization_id": {
          "type": "string",
          "minLength": 1
        },
        "ownership_evidence_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "ownership_event_at": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "assignee": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "assignee_id",
        "name",
        "type",
        "organization_id",
        "separate_organization",
        "linkedin_profile_ref",
        "partner_business_manager_id",
        "business_manager_role",
        "invitation_status",
        "invitation_evidence_id",
        "invitation_event_at",
        "admin_exception",
        "notes"
      ],
      "properties": {
        "assignee_id": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "type": {
          "enum": [
            "PERSON",
            "PARTNER"
          ]
        },
        "organization_id": {
          "type": "string",
          "minLength": 1
        },
        "separate_organization": {
          "type": "boolean"
        },
        "linkedin_profile_ref": {
          "type": [
            "string",
            "null"
          ]
        },
        "partner_business_manager_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "business_manager_role": {
          "enum": [
            "ADMIN",
            "EMPLOYEE",
            "CONTRACTOR",
            null
          ]
        },
        "invitation_status": {
          "enum": [
            "NOT_REQUIRED",
            "NOT_SENT",
            "PENDING",
            "ACCEPTED",
            "DECLINED",
            "UNKNOWN"
          ]
        },
        "invitation_evidence_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "invitation_event_at": {
          "type": [
            "string",
            "null"
          ]
        },
        "admin_exception": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "reason_code",
            "decision",
            "reviewer_id",
            "decided_at",
            "expires_at",
            "evidence_id"
          ],
          "properties": {
            "reason_code": {
              "type": [
                "string",
                "null"
              ]
            },
            "decision": {
              "type": [
                "string",
                "null"
              ]
            },
            "reviewer_id": {
              "type": [
                "string",
                "null"
              ]
            },
            "decided_at": {
              "type": [
                "string",
                "null"
              ]
            },
            "expires_at": {
              "type": [
                "string",
                "null"
              ]
            },
            "evidence_id": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        },
        "notes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "assets": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "asset_id",
          "required",
          "type",
          "name",
          "native_id",
          "relationship",
          "owner_organization_id",
          "ownership_evidence_id",
          "ownership_event_at",
          "task_code",
          "required_capabilities",
          "prohibited_capabilities",
          "requested_role",
          "scope_decision",
          "role_exception",
          "request",
          "approval",
          "verification",
          "notes"
        ],
        "properties": {
          "asset_id": {
            "type": "string",
            "minLength": 1
          },
          "required": {
            "type": "boolean"
          },
          "type": {
            "enum": [
              "AD_ACCOUNT",
              "PAGE"
            ]
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "native_id": {
            "type": "string",
            "minLength": 1
          },
          "relationship": {
            "enum": [
              "OWNED",
              "SHARED"
            ]
          },
          "owner_organization_id": {
            "type": "string",
            "minLength": 1
          },
          "ownership_evidence_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "ownership_event_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "task_code": {
            "enum": [
              "REPORTING",
              "CAMPAIGN_EDITING",
              "CREATIVE_EDITING",
              "BILLING",
              "ACCOUNT_ADMINISTRATION",
              "SPONSOR_CONTENT",
              "LEAD_FORM_DOWNLOAD",
              "LANDING_PAGE_EDIT",
              "PAGE_CONTENT",
              "PAGE_ANALYTICS",
              "PAGE_ADMINISTRATION"
            ]
          },
          "required_capabilities": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1,
            "uniqueItems": true,
            "items": {
              "enum": [
                "REPORTING",
                "CAMPAIGN_EDITING",
                "CREATIVE_EDITING",
                "BILLING",
                "ACCOUNT_ADMINISTRATION",
                "SPONSOR_CONTENT",
                "LEAD_FORM_DOWNLOAD",
                "LANDING_PAGE_EDIT",
                "PAGE_CONTENT",
                "PAGE_ANALYTICS",
                "PAGE_ADMINISTRATION"
              ]
            }
          },
          "prohibited_capabilities": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "enum": [
                "REPORTING",
                "CAMPAIGN_EDITING",
                "CREATIVE_EDITING",
                "BILLING",
                "ACCOUNT_ADMINISTRATION",
                "SPONSOR_CONTENT",
                "LEAD_FORM_DOWNLOAD",
                "LANDING_PAGE_EDIT",
                "PAGE_CONTENT",
                "PAGE_ANALYTICS",
                "PAGE_ADMINISTRATION"
              ]
            }
          },
          "requested_role": {
            "type": "string",
            "minLength": 1
          },
          "scope_decision": {
            "enum": [
              "EXACT",
              "BROADER_APPROVED",
              "BROADER_REJECTED",
              "UNKNOWN"
            ]
          },
          "role_exception": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "reason_code",
              "decision",
              "reviewer_id",
              "decided_at",
              "expires_at",
              "evidence_id"
            ],
            "properties": {
              "reason_code": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "decision": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "reviewer_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "decided_at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "expires_at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "evidence_id": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "request": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "status",
              "requester_id",
              "approver_id",
              "event_at",
              "evidence_id"
            ],
            "properties": {
              "status": {
                "enum": [
                  "NOT_SUBMITTED",
                  "SUBMITTED",
                  "UNKNOWN"
                ]
              },
              "requester_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "approver_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "event_at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "evidence_id": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "approval": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "decision",
              "approver_id",
              "approved_role",
              "event_at",
              "evidence_id"
            ],
            "properties": {
              "decision": {
                "enum": [
                  "APPROVED",
                  "REJECTED",
                  "PENDING",
                  "UNKNOWN"
                ]
              },
              "approver_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "approved_role": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "event_at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "evidence_id": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "verification": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "assignee_id",
              "task_code",
              "task_template_id",
              "outcome",
              "observations_valid",
              "event_at",
              "evidence_id"
            ],
            "properties": {
              "assignee_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "task_code": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "task_template_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "outcome": {
                "enum": [
                  "SUCCEEDED",
                  "DENIED",
                  "ERROR",
                  "PENDING",
                  "NOT_RUN",
                  "UNKNOWN"
                ]
              },
              "observations_valid": {
                "type": "boolean"
              },
              "event_at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "evidence_id": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "notes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    },
    "evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "evidence_id",
          "kind",
          "subject_type",
          "subject_id",
          "actor_id",
          "event_at",
          "captured_at",
          "reference",
          "owner_id",
          "capability",
          "task_template_id",
          "asserted_owner_organization_id",
          "recipient_organization_id"
        ],
        "properties": {
          "evidence_id": {
            "type": "string",
            "minLength": 1
          },
          "kind": {
            "enum": [
              "IDENTITY_VERIFICATION",
              "BUSINESS_MANAGER_OWNERSHIP",
              "ASSET_OWNERSHIP",
              "PERSON_INVITATION",
              "ACCESS_REQUEST",
              "ACCESS_APPROVAL",
              "ROLE_EXCEPTION",
              "NATIVE_TASK",
              "SHARED_ASSET"
            ]
          },
          "subject_type": {
            "enum": [
              "IDENTITY",
              "BUSINESS_MANAGER",
              "ASSET",
              "ASSIGNEE"
            ]
          },
          "subject_id": {
            "type": "string",
            "minLength": 1
          },
          "actor_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "event_at": {
            "type": "string",
            "format": "date-time",
            "pattern": "Z$"
          },
          "captured_at": {
            "type": "string",
            "format": "date-time",
            "pattern": "Z$"
          },
          "reference": {
            "type": "string",
            "pattern": "^((https://)|(urn:)|(fictional://receipt/))"
          },
          "owner_id": {
            "type": "string",
            "minLength": 1
          },
          "capability": {
            "enum": [
              "REPORTING",
              "CAMPAIGN_EDITING",
              "CREATIVE_EDITING",
              "BILLING",
              "ACCOUNT_ADMINISTRATION",
              "SPONSOR_CONTENT",
              "LEAD_FORM_DOWNLOAD",
              "LANDING_PAGE_EDIT",
              "PAGE_CONTENT",
              "PAGE_ANALYTICS",
              "PAGE_ADMINISTRATION",
              null
            ]
          },
          "task_template_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "asserted_owner_organization_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "recipient_organization_id": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "external_requests": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "request_id",
          "status",
          "blocking",
          "global_blocker",
          "owner_id",
          "next_action",
          "blocked_nodes"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "minLength": 1
          },
          "status": {
            "enum": [
              "OPEN",
              "RESOLVED",
              "NOT_APPLICABLE"
            ]
          },
          "blocking": {
            "type": "boolean"
          },
          "global_blocker": {
            "type": "boolean"
          },
          "owner_id": {
            "type": "string",
            "minLength": 1
          },
          "next_action": {
            "type": "string",
            "minLength": 1
          },
          "blocked_nodes": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "asset_id",
                "node"
              ],
              "properties": {
                "asset_id": {
                  "type": "string",
                  "minLength": 1
                },
                "node": {
                  "enum": [
                    "OWNERSHIP",
                    "ROLE",
                    "REQUEST",
                    "APPROVAL",
                    "VERIFICATION"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "notes": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://maestrogtm.com/schemas/linkedin-business-manager-record-v2.json"
}
