{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://eq-sync/schema/eq-sync-1.json",
  "title": "eq-sync webhook payload",
  "description": "One request per event. Field names inside \"invoice\" are the field names used by the portal; personal fields are removed. New fields may be added; existing fields are not removed within schema eq-sync/1.",
  "type": "object",
  "required": [
    "schema",
    "event",
    "sentAt",
    "idempotencyKey",
    "source"
  ],
  "properties": {
    "schema": {
      "const": "eq-sync/1"
    },
    "event": {
      "enum": [
        "invoice.upsert",
        "invoice.removed",
        "month.summary",
        "test"
      ]
    },
    "sentAt": {
      "type": "string",
      "format": "date-time"
    },
    "idempotencyKey": {
      "type": "string",
      "description": "Same value = same event; safe to ignore duplicates. Also sent as the Idempotency-Key header."
    },
    "source": {
      "type": "object",
      "required": [
        "app",
        "version",
        "receiver"
      ],
      "properties": {
        "app": {
          "const": "eq-sync"
        },
        "version": {
          "type": "string"
        },
        "receiver": {
          "type": "object",
          "properties": {
            "tin": {
              "type": [
                "string",
                "null"
              ]
            },
            "name": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        }
      }
    },
    "change": {
      "enum": [
        "new",
        "changed",
        "pdf"
      ],
      "description": "invoice.upsert only. \"pdf\": the invoice is unchanged, its PDF is sent now."
    },
    "invoice": {
      "type": "object",
      "required": [
        "id",
        "serialNumber",
        "status",
        "type",
        "kind",
        "createdAt"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "serialNumber": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "kind": {
          "type": "string"
        },
        "version": {
          "type": [
            "integer",
            "null"
          ]
        },
        "createdAt": {
          "type": "string"
        },
        "lastUpdatedAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "amount": {
          "type": [
            "number",
            "null"
          ]
        },
        "vat": {
          "type": [
            "number",
            "null"
          ]
        },
        "sender": {
          "type": "object",
          "properties": {
            "tin": {
              "type": [
                "string",
                "null"
              ]
            },
            "name": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        },
        "receiver": {
          "type": "object",
          "properties": {
            "tin": {
              "type": [
                "string",
                "null"
              ]
            },
            "name": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        },
        "items": {
          "type": "array",
          "items": {
            "type": "object"
          }
        }
      },
      "additionalProperties": true
    },
    "pdf": {
      "type": [
        "object",
        "null"
      ],
      "required": [
        "fileName",
        "contentType",
        "sha256",
        "base64"
      ],
      "properties": {
        "fileName": {
          "type": "string"
        },
        "contentType": {
          "const": "application/pdf"
        },
        "sha256": {
          "type": "string"
        },
        "base64": {
          "type": "string"
        }
      }
    },
    "month": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}$"
    },
    "period": {
      "type": "object",
      "properties": {
        "from": {
          "type": "string"
        },
        "to": {
          "type": "string"
        }
      }
    },
    "counts": {
      "type": "object",
      "properties": {
        "inScope": {
          "type": "integer"
        },
        "sent": {
          "type": "integer"
        },
        "removed": {
          "type": "integer"
        },
        "failed": {
          "type": "integer"
        }
      }
    },
    "invoiceIds": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "month.summary: every invoice id in scope for the month (for reconciliation)."
    }
  }
}
