{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/insuremo-com/json-schema/insuremo-com-comm-binding-save-request-schema.json",
  "title": "CommBindingSaveRequest",
  "description": "Create or save a delivery rule owned by a communication definition. Replacement clears omitted optional fields. Policy links, preference/retry overrides and conditions are removed; documents become empty and archival obligations become NONE. A retry override requires all four fields.",
  "x-generated": "2026-12-02",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/insuremo-com-connecthub-openapi.yml#/components/schemas/CommBindingSaveRequest",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "Attachments": {
      "type": "array",
      "description": "Per-document delivery instructions. Omission or an empty array removes existing instructions and sends no managed documents; null is invalid.",
      "items": {
        "$ref": "#/$defs/CommBindingAttachmentInput"
      },
      "writeOnly": true
    },
    "BindingId": {
      "type": "integer",
      "format": "int64",
      "description": "Omit or send null to create. Supply the existing delivery rule identifier to save it."
    },
    "Channel": {
      "type": "string",
      "description": "Channel used by this delivery rule.",
      "writeOnly": true
    },
    "ConditionExpression": {
      "type": "string",
      "description": "Optional condition over declared variable names. Omission, null or blank clears it. Refer to variables directly, for example PolicyNo, without a Context or Payload prefix.",
      "maxLength": 500,
      "writeOnly": true
    },
    "DefinitionId": {
      "type": "integer",
      "format": "int64",
      "description": "Owning communication definition identifier. Required on creation. When saving an existing rule, a supplied non-null identifier must match its owner."
    },
    "DeliveryPolicyId": {
      "type": "integer",
      "format": "int64",
      "description": "Optional reusable delivery policy. Omission or null removes the time/frequency restriction."
    },
    "Enabled": {
      "type": "string",
      "description": "Y enables this rule and N disables it. Omission on creation defaults to Y; required when saving an existing rule. Rule enablement is part of save; definitions have dedicated enable/disable endpoints because enabling gates runtime immutability.",
      "enum": [
        "Y",
        "N"
      ],
      "writeOnly": true
    },
    "ExpectedRevision": {
      "type": "integer",
      "format": "int64",
      "description": "Last read Revision; required when changing an existing resource. Bindings use the owning Definition Revision."
    },
    "GroupId": {
      "type": "integer",
      "format": "int64",
      "description": "Required DataIO publication group identifier; rows of a locked group cannot be published.",
      "writeOnly": true
    },
    "MaxAttempts": {
      "type": "integer",
      "format": "int32",
      "description": "Set all four retry fields for a custom Rule policy; all null inherits.",
      "minimum": 1,
      "writeOnly": true
    },
    "OrderNo": {
      "type": "integer",
      "format": "int32",
      "description": "FALLBACK candidate order: positive and unique within the canonical recipient role. ALL does not use this field to guarantee delivery order and permits ties.",
      "writeOnly": true
    },
    "OutputContract": {
      "$ref": "#/$defs/CommFileOutputContractInput"
    },
    "Parameters": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/CommParameterInput"
      },
      "description": "Named VARIABLE/CONSTANT parameter sources; omission clears local configuration."
    },
    "PreferencePolicy": {
      "type": "string",
      "description": "Omission or null clears the override and inherits the Definition policy.",
      "enum": [
        "RESPECT",
        "BYPASS",
        "RESPECT",
        "BYPASS"
      ],
      "writeOnly": true
    },
    "ReceiptMode": {
      "type": "string",
      "description": "Explicit DELIVERY completion policy ACCEPTED or DELIVERED; absent for DOCUMENT.",
      "enum": [
        "DELIVERED",
        "ACCEPTED"
      ]
    },
    "ReceiptTimeoutSeconds": {
      "type": "integer",
      "format": "int32",
      "description": "DELIVERED receipt timeout in seconds; absent for ACCEPTED.",
      "maximum": 604800,
      "minimum": 1
    },
    "RecipientAddressVariable": {
      "type": "string",
      "description": "Declared variable containing the recipient address as a string. Required for CONTEXT; omit or use null/blank for REQUEST.",
      "writeOnly": true
    },
    "RecipientIdVariable": {
      "type": "string",
      "description": "Declared variable containing the recipient RecipientId. Must be omitted, null or blank for REQUEST. For CONTEXT it is required when the resolved PreferencePolicy is RESPECT.",
      "writeOnly": true
    },
    "RecipientRole": {
      "type": "string",
      "description": "Optional for EMAIL; omission uses the default email address group. Explicit legacy roles remain supported. Other channels retain their routing group key. A definition permits one Binding per canonical group and channel.",
      "maxLength": 40,
      "writeOnly": true
    },
    "RecipientSource": {
      "type": "string",
      "description": "REQUEST selects explicit Recipients. EMAIL Role may be omitted; its Address or Addresses supplies To. CONTEXT reads declared Variables; an EMAIL address Variable may be a string or nonempty string list.",
      "enum": [
        "CONTEXT",
        "REQUEST"
      ],
      "writeOnly": true
    },
    "RenderMode": {
      "type": "string",
      "description": "HUB renders the template selected by its tenant-unique code; SERVICE passes TemplateCode and extracted typed Variables to the delivery driver.",
      "enum": [
        "SERVICE",
        "HUB"
      ],
      "writeOnly": true
    },
    "RetryBackoffMultiplier": {
      "type": "number",
      "description": "JSON number from 1 to 100 with at most four fractional digits. Supply all four retry fields explicitly to replace or clear an existing override.",
      "maximum": 100,
      "minimum": 1,
      "multipleOf": 0.0001,
      "writeOnly": true
    },
    "RetryInitialDelaySeconds": {
      "type": "integer",
      "format": "int32",
      "description": "Initial automatic retry delay in seconds. Supply all four retry fields to override the Definition.",
      "minimum": 1,
      "writeOnly": true
    },
    "RetryMaxDelaySeconds": {
      "type": "integer",
      "format": "int32",
      "description": "Maximum automatic retry delay in seconds. Supply all four retry fields to override the Definition.",
      "minimum": 1,
      "writeOnly": true
    },
    "ServiceCode": {
      "type": "string",
      "description": "Registered delivery service used by this rule. Its driver and Settings select transport behavior; integration-adapter configuration is optional and belongs to that driver.",
      "maxLength": 60,
      "writeOnly": true
    },
    "TemplateCode": {
      "type": "string",
      "description": "Tenant-local template code. Required for DELIVERY or DOCUMENT with GENERATE; optional for ARCHIVE-only DOCUMENT. Provider identifiers belong to Template.ProviderTemplateReference.",
      "maxLength": 100,
      "writeOnly": true
    }
  },
  "required": [
    "GroupId"
  ],
  "$defs": {
    "CommBindingAttachmentInput": {
      "type": "object",
      "additionalProperties": false,
      "description": "Per-document delivery instructions. Omission or an empty array removes existing instructions and sends no managed documents; null is invalid.",
      "properties": {
        "FileKey": {
          "type": "string",
          "description": "FileKey of a Task input attachment.",
          "maxLength": 60
        },
        "Required": {
          "type": "boolean",
          "description": "Reject Task submission when this attachment is unavailable for an enabled, condition-matched Binding. Optional missing inputs do not block acceptance."
        }
      },
      "required": [
        "FileKey",
        "Required"
      ]
    },
    "CommFileLimitsInput": {
      "type": "object",
      "additionalProperties": false,
      "description": "Explicit file Limits contract.",
      "properties": {
        "MaxFileBytes": {
          "type": "integer",
          "format": "int64"
        },
        "MaxFiles": {
          "type": "integer",
          "format": "int32"
        },
        "MaxTotalBytes": {
          "type": "integer",
          "format": "int64"
        }
      }
    },
    "CommFileOutputContractInput": {
      "type": "object",
      "additionalProperties": false,
      "description": "NONE or complete FIXED/DYNAMIC archival obligation frozen at acceptance.",
      "properties": {
        "ArchiveRequirement": {
          "type": "string",
          "enum": [
            "NONE",
            "OPTIONAL",
            "REQUIRED"
          ]
        },
        "Entries": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/CommFileOutputEntryInput"
          }
        },
        "Limits": {
          "$ref": "#/$defs/CommFileLimitsInput"
        },
        "Mode": {
          "type": "string",
          "enum": [
            "FIXED",
            "DYNAMIC"
          ]
        },
        "Roles": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/CommFileOutputRoleInput"
          }
        }
      }
    },
    "CommFileOutputEntryInput": {
      "type": "object",
      "additionalProperties": false,
      "description": "Explicit file OutputEntry contract.",
      "properties": {
        "FileKey": {
          "type": "string"
        },
        "Role": {
          "type": "string"
        }
      }
    },
    "CommFileOutputRoleInput": {
      "type": "object",
      "additionalProperties": false,
      "description": "Explicit file OutputRole contract.",
      "properties": {
        "MaxCount": {
          "type": "integer",
          "format": "int32"
        },
        "MinCount": {
          "type": "integer",
          "format": "int32"
        },
        "Role": {
          "type": "string"
        }
      }
    },
    "CommParameterInput": {
      "type": "object",
      "additionalProperties": false,
      "description": "Source VARIABLE requires Binding and forbids Value; Required applies only to VARIABLE. Source CONSTANT requires Value, including explicit null, and forbids Binding and Required. The API validates these conditions.",
      "properties": {
        "Binding": {
          "type": "string",
          "description": "Exact Context Variable name; required for VARIABLE, forbidden for CONSTANT."
        },
        "Required": {
          "type": "boolean",
          "description": "VARIABLE only; default false. Inherited Service requiredness cannot be weakened."
        },
        "Source": {
          "type": "string",
          "description": "VARIABLE requires Binding and forbids Value, including null. CONSTANT requires the Value property and forbids Binding and Required, even when null or false. Switching Source must remove fields belonging to the previous source.",
          "enum": [
            "VARIABLE",
            "CONSTANT"
          ]
        },
        "Value": {
          "description": "CONSTANT only; property required, nullable native JSON literal. Omit this property entirely for VARIABLE, including when its value would be null. Built-in EMAIL Cc requires a native JSON array of plain email addresses; null or an empty array means no Cc. Accepts a native JSON string, number, boolean, array, object or null; conditional applicability is validated by the API."
        }
      },
      "required": [
        "Source"
      ]
    }
  }
}