{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/assinafy-com-br/json-schema/assinafy-com-br-document-contract-schema.json",
  "title": "DocumentContract",
  "description": "The contract terms tracked on a document.",
  "x-generated": "2026-11-01",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/assinafy-com-br-openapi.json#/components/schemas/DocumentContract",
  "properties": {
    "resource": {
      "type": "string"
    },
    "document_id": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": [
        "draft",
        "active",
        "expired",
        "terminated"
      ]
    },
    "counterparty_name": {
      "type": [
        "string",
        "null"
      ]
    },
    "counterparty_taxpayer_id": {
      "description": "CPF or CNPJ, digits only.",
      "type": [
        "string",
        "null"
      ]
    },
    "value": {
      "description": "Two decimal places at most.",
      "type": [
        "number",
        "null"
      ]
    },
    "currency": {
      "description": "ISO 4217 code; `BRL` when a value is sent without one.",
      "type": [
        "string",
        "null"
      ]
    },
    "start_date": {
      "type": [
        "string",
        "null"
      ],
      "format": "date"
    },
    "end_date": {
      "type": [
        "string",
        "null"
      ],
      "format": "date"
    },
    "auto_renew": {
      "type": "boolean"
    },
    "renewal_term_months": {
      "type": [
        "integer",
        "null"
      ]
    },
    "notice_period_days": {
      "type": [
        "integer",
        "null"
      ]
    },
    "term": {
      "description": "Steps on every renewal, starting at 1.",
      "type": "integer"
    },
    "owner_id": {
      "description": "ID of the workspace member who owns the contract. When the owner is no longer a member of the workspace (removed, left, or deleted with their account), the hourly run hands the contract to the first owner who is still an active member, or leaves it without one; an inactive member stays the owner. The contract's e-mails (renewal notice, expiring, expired, renewed) go to the first of the owner and the document's creator who is an active member, as that member's notification preferences allow.",
      "type": [
        "string",
        "null"
      ]
    },
    "metadata": {
      "description": "Up to 50 keys of your own, each holding text of at most 500 characters; `null` when there are none. A key ending in `_at` cannot hold a number: the API returns numbers under such keys as dates.",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": {
        "type": "string"
      }
    },
    "external_references": {
      "description": "IDs outside systems use for this contract, ordered by system and id.",
      "type": "array",
      "items": {
        "properties": {
          "system": {
            "type": "string"
          },
          "id": {
            "type": "string"
          }
        },
        "type": "object"
      }
    },
    "document": {
      "$ref": "#/$defs/Document",
      "description": "Only with `expand=document`: the document the terms are tracked on."
    },
    "amendments": {
      "description": "Only on the single-contract read: the documents that amend, renew or terminate this contract, the applied ones first by `number`, then the pending ones.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/DocumentContractAmendment"
      }
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    }
  },
  "type": "object",
  "$defs": {
    "Assignment": {
      "description": "A request for signers to sign a document.",
      "properties": {
        "resource": {
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "document_id": {
          "description": "The document this assignment belongs to. `null` only if the document was deleted.",
          "type": [
            "string",
            "null"
          ]
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "sender_email": {
          "description": "Email of the user who sent the document; null once that user has deleted their account.",
          "type": [
            "string",
            "null"
          ],
          "format": "email"
        },
        "method": {
          "type": "string",
          "enum": [
            "virtual",
            "collect"
          ]
        },
        "expires_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "message": {
          "type": [
            "string",
            "null"
          ]
        },
        "signers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AssignmentSigner"
          }
        },
        "copy_receivers": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AssignmentItem"
          }
        },
        "summary": {
          "$ref": "#/$defs/AssignmentSummary"
        },
        "signing_urls": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/SigningUrl"
          }
        }
      },
      "type": "object"
    },
    "AssignmentItem": {
      "properties": {
        "id": {
          "type": "string"
        },
        "page": {
          "oneOf": [
            {
              "$ref": "#/$defs/DocumentPage"
            },
            {
              "type": "null"
            }
          ]
        },
        "signer": {
          "description": "Signer responsible for this item.",
          "type": "object"
        },
        "field": {
          "description": "Field definition associated with the item.",
          "type": [
            "object",
            "null"
          ]
        },
        "display_settings": {
          "description": "Rendering metadata for the item. Collect items use the DisplaySettings schema; virtual and legacy items may return an empty or non-object value."
        },
        "value": {
          "description": "Captured value when completed; `null` until then."
        },
        "completed": {
          "type": "boolean"
        }
      },
      "type": "object"
    },
    "AssignmentSigner": {
      "description": "A signer within an assignment: the base Signer plus per-assignment verification/notification details.",
      "type": "object",
      "allOf": [
        {
          "$ref": "#/$defs/Signer"
        },
        {
          "properties": {
            "verification_method": {
              "type": [
                "string",
                "null"
              ]
            },
            "notification_methods": {
              "type": [
                "array",
                "null"
              ],
              "items": {
                "type": "string"
              }
            },
            "step": {
              "description": "Sequential signing step (defaults to 1).",
              "type": [
                "integer",
                "null"
              ]
            },
            "notified": {
              "type": [
                "boolean",
                "null"
              ]
            },
            "identity_verification_status": {
              "description": "Latest identity-document verification status; `InReview` means the account must decide it before the document can be certificated.",
              "type": [
                "string",
                "null"
              ],
              "enum": [
                "Pending",
                "InReview",
                "Approved",
                "Declined",
                "Expired",
                "Abandoned"
              ]
            },
            "completed": {
              "description": "Only present in account-owner contexts.",
              "type": [
                "boolean",
                "null"
              ]
            },
            "notification_history": {
              "description": "Per-channel delivery history for this signer (email + WhatsApp), most-recent send order.",
              "type": [
                "array",
                "null"
              ],
              "items": {
                "$ref": "#/$defs/NotificationHistoryEntry"
              }
            }
          },
          "type": "object"
        }
      ]
    },
    "AssignmentSummary": {
      "properties": {
        "signer_count": {
          "type": "integer"
        },
        "completed_count": {
          "type": "integer"
        },
        "signers": {
          "type": "array",
          "items": {
            "type": "object"
          }
        }
      },
      "type": "object"
    },
    "Document": {
      "description": "A document and its current lifecycle state.",
      "properties": {
        "resource": {
          "description": "Present in single-resource responses.",
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "account_id": {
          "type": "string"
        },
        "template_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "name": {
          "type": "string"
        },
        "status": {
          "description": "Status code — see GET /v1/documents/statuses.",
          "type": "string"
        },
        "artifacts": {
          "description": "Artifact download URLs keyed by name. Always `original`, plus `thumbnail` once one exists. A certificated document also carries `certificated`, `certificate-page` and `bundle`, and `pades` when it was signed with a digital certificate — the PAdES version holds the signers' ICP-Brasil signatures, which certification flattens out of the certificated PDF.",
          "type": "object"
        },
        "is_closed": {
          "type": "boolean"
        },
        "signing_url": {
          "type": "string"
        },
        "verification_code": {
          "description": "The code printed on the certificate page. Anyone can check it with `GET /v1/documents/{verification_code}/verify` or on `verification_url`. `null` until the document is `certificated`, and on documents certificated before verification codes existed.",
          "type": [
            "string",
            "null"
          ]
        },
        "verification_url": {
          "description": "The public verification page for this document. `null` until the document is `certificated`.",
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "decline_reason": {
          "type": [
            "string",
            "null"
          ]
        },
        "declined_by": {
          "oneOf": [
            {
              "$ref": "#/$defs/Signer"
            },
            {
              "type": "null"
            }
          ]
        },
        "tags": {
          "type": "array",
          "items": {
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            },
            "type": "object"
          }
        },
        "assignment": {
          "description": "The document's assignment, or `null` before one is created. The server decides when it is included, whatever `expand` the request sends: the document list, `GET /v1/documents/{documentId}`, the signer's document list and document creation from a template always include it; `/documents/search` and the upload response never do. Only the rename response follows `?expand=assignment`.",
          "oneOf": [
            {
              "$ref": "#/$defs/Assignment"
            },
            {
              "type": "null"
            }
          ]
        },
        "pages": {
          "description": "The document's pages. Included on the same responses as `assignment`, and also on the upload response.",
          "type": "array",
          "items": {
            "$ref": "#/$defs/DocumentPage"
          }
        },
        "has_contract": {
          "description": "Only on `GET /v1/documents/{documentId}` read by the workspace, while the environment has contract tracking on: not with a signer's access code, not in document lists or webhooks, and left out when the lookup fails, so a missing key means unknown. Whether `GET /v1/accounts/{accountId}/documents/{documentId}/contract` answers with contract terms, the document's own or those of a contract it amends whose document still exists, so a page can lay out the contract section before reading it.",
          "type": "boolean"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        }
      },
      "type": "object"
    },
    "DocumentContractAmendment": {
      "description": "A document that amends, renews or terminates a contract: its link and the terms it changes. The parent's terms take the delta once this document is certificated; until then the parent is untouched.",
      "properties": {
        "resource": {
          "type": "string"
        },
        "document_id": {
          "description": "This document, the instrument.",
          "type": "string"
        },
        "document_name": {
          "description": "This document's name.",
          "type": "string"
        },
        "parent_document_id": {
          "description": "The contract document whose terms change.",
          "type": "string"
        },
        "relation_type": {
          "type": "string",
          "enum": [
            "amendment",
            "renewal",
            "termination"
          ]
        },
        "number": {
          "description": "Position among the parent's applied amendments by signing date; `null` while pending.",
          "type": [
            "integer",
            "null"
          ]
        },
        "status": {
          "description": "`applied` once the delta moved the parent's terms.",
          "type": "string",
          "enum": [
            "pending",
            "applied"
          ]
        },
        "document_status": {
          "description": "This document's own status, so a declined, cancelled or expired instrument shows as such. An instrument applies only while its document is `certificated`: one whose document reads `failed` after it was signed waits, with no `apply_error`, until it is certificated again, and then applies in its place in the signing order.",
          "type": "string"
        },
        "apply_error": {
          "description": "Why a signed instrument has not applied yet, retried every hour: the workspace's plan does not include contract tracking (it applies on the first run after the plan returns), the parent would not take the delta, an instrument signed before this one has not applied yet, one signed after it has already applied (this one then stays blocked: unlink it, and record what it still changes on a new instrument), or an unexpected failure.",
          "type": [
            "string",
            "null"
          ]
        },
        "currency": {
          "description": "The currency of the amounts in `terms` and `changes`. Once applied, the contract's currency at that moment, kept whatever the contract moves to later. While pending (and for an instrument applied before this was kept), the one this instrument moves the contract to, otherwise the contract's. `null` when neither has one.",
          "type": [
            "string",
            "null"
          ]
        },
        "terms": {
          "description": "The delta: only the terms this instrument changes; `null` when it changes none (a termination on the day it is signed).",
          "type": [
            "object",
            "null"
          ]
        },
        "changes": {
          "description": "Every parent field the roll-up moves, as `{from, to}`: a preview while pending, the record once applied; `null` when it moves none.",
          "type": [
            "object",
            "null"
          ]
        },
        "applied_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        }
      },
      "type": "object"
    },
    "DocumentPage": {
      "properties": {
        "id": {
          "type": "string"
        },
        "number": {
          "type": "integer"
        },
        "height": {
          "type": "integer"
        },
        "width": {
          "type": "integer"
        },
        "download_url": {
          "type": "string"
        }
      },
      "type": "object"
    },
    "NotificationHistoryEntry": {
      "description": "A single notification delivery record for a signer channel.",
      "properties": {
        "event": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "sent",
            "failed"
          ]
        },
        "error_code": {
          "type": [
            "string",
            "null"
          ]
        },
        "error_message": {
          "type": [
            "string",
            "null"
          ]
        },
        "sent_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "failed_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      },
      "type": "object"
    },
    "Signer": {
      "description": "A signing party belonging to a workspace account.",
      "properties": {
        "resource": {
          "description": "Present in single-resource responses.",
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "full_name": {
          "type": "string"
        },
        "email": {
          "type": [
            "string",
            "null"
          ],
          "format": "email"
        },
        "whatsapp_phone_number": {
          "description": "E.164 format; normalized on save.",
          "type": [
            "string",
            "null"
          ]
        },
        "government_id": {
          "description": "Signer's normalized CPF (11 digits) or CNPJ (14 characters; may be alphanumeric).",
          "type": [
            "string",
            "null"
          ]
        },
        "has_accepted_terms": {
          "type": "boolean"
        }
      },
      "type": "object"
    },
    "SigningUrl": {
      "properties": {
        "signer_id": {
          "type": "string"
        },
        "url": {
          "type": "string"
        }
      },
      "type": "object"
    }
  }
}