{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/infocert/main/json-schema/infocert-create-process-type-schema.json",
  "title": "CreateProcessType",
  "description": "Creation of a Process Type.",
  "x-generated": "2026-10-18",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/infocert-gonotice-openapi.yml#/components/schemas/CreateProcessType",
  "type": "object",
  "properties": {
    "externalID": {
      "type": "string",
      "description": "Optional external identifier provided by the caller"
    },
    "processTypeName": {
      "type": "string",
      "description": "Process type name"
    },
    "sendingPolicy": {
      "description": "Sending policy (validated based on selected channel)"
    },
    "certificationLevels": {
      "$ref": "#/$defs/ProcessTypeCertificationLevels",
      "description": "Certification levels to generate"
    },
    "smsChannel": {
      "$ref": "#/$defs/smsChannel",
      "description": "SMS Channel"
    },
    "emailChannel": {
      "$ref": "#/$defs/emailChannel",
      "description": "Email Channel"
    },
    "whatsappChannel": {
      "$ref": "#/$defs/whatsappChannel",
      "description": "WhatsApp Channel"
    },
    "externalChannel": {
      "$ref": "#/$defs/externalChannel",
      "description": "External Channel"
    },
    "attachments": {
      "description": "Zero or more common attachments",
      "type": "object",
      "properties": {
        "content": {
          "description": "Array of attachments",
          "type": "array",
          "items": {
            "$ref": "#/$defs/Attachment"
          }
        },
        "certificationLevel": {
          "description": "Certification level",
          "type": "string",
          "enum": [
            "None",
            "AttachmentOpened"
          ]
        },
        "additionalAttachmentCount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9,
          "description": "Zero or more attachments to be added in the single dispatches"
        }
      }
    },
    "rejectReasons": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/RejectReason"
      },
      "description": "Reject reasons",
      "default": []
    },
    "failoverChannels": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/FailoverChannel"
      },
      "description": "Failover channels",
      "default": []
    },
    "reminderConfiguration": {
      "$ref": "#/$defs/ReminderConfiguration",
      "description": "Optional reminder configuration"
    }
  },
  "oneOf": [
    {
      "required": [
        "processTypeName",
        "smsChannel"
      ]
    },
    {
      "required": [
        "processTypeName",
        "emailChannel"
      ]
    },
    {
      "required": [
        "processTypeName",
        "whatsappChannel"
      ]
    },
    {
      "required": [
        "processTypeName",
        "externalChannel"
      ]
    }
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "externalChannel": {
            "type": "object"
          }
        },
        "required": [
          "externalChannel"
        ]
      },
      "then": {
        "properties": {
          "sendingPolicy": {
            "$ref": "#/$defs/ExternalChannelSendingPolicy"
          }
        },
        "required": [
          "sendingPolicy"
        ]
      },
      "else": {
        "properties": {
          "sendingPolicy": {
            "$ref": "#/$defs/SendingPolicy"
          }
        },
        "required": [
          "sendingPolicy"
        ]
      }
    }
  ],
  "additionalProperties": false,
  "$defs": {
    "Attachment": {
      "title": "Attachment",
      "type": "object",
      "properties": {
        "name": {
          "description": "Descriptive name of the attachment. Can be shown to the users and recipients.",
          "type": "string"
        },
        "filename": {
          "description": "Filename with extension but without path",
          "type": "string"
        },
        "size": {
          "description": "File size in KB",
          "type": "number",
          "format": "int32",
          "minimum": 0
        },
        "mimeType": {
          "description": "The only format supported is PDF, a validation error has to occur when using a different file type",
          "type": "string"
        },
        "url": {
          "description": "Path to attachment content",
          "type": "string"
        },
        "template": {
          "description": "If true the attachment is a template",
          "type": "boolean"
        },
        "placeholders": {
          "description": "List of placeholders",
          "type": "array",
          "items": {
            "type": "string"
          },
          "default": []
        }
      },
      "required": [
        "name",
        "filename",
        "mimeType"
      ]
    },
    "ExternalChannelSendingPolicy": {
      "title": "ExternalChannelSendingPolicy",
      "type": "object",
      "description": "Sending policy for external channel dispatches. Same validation rule: if numberOfRetries > 1 then frequency must be > 0.",
      "properties": {
        "timeout": {
          "type": "integer",
          "minimum": 1,
          "description": "Overall timeout before the dispatch expires (unit defined by backend)"
        }
      },
      "required": [
        "timeout"
      ],
      "additionalProperties": false
    },
    "FailoverChannel": {
      "title": "FailoverChannel",
      "type": "object",
      "description": "Fallback channel configuration used when the primary channel cannot be delivered.",
      "properties": {
        "channelPriority": {
          "type": "integer",
          "minimum": 0,
          "description": "0 is the first failover to try, then 1, ..."
        },
        "channelName": {
          "type": "string",
          "enum": [
            "emailChannel",
            "smsChannel",
            "whatsappChannel"
          ],
          "description": "Target channel"
        },
        "channelDetails": {
          "type": "object",
          "oneOf": [
            {
              "$ref": "#/$defs/emailChannel"
            },
            {
              "$ref": "#/$defs/smsChannel"
            }
          ],
          "description": "Payload for the failover channel (email-like or sms-like)."
        }
      },
      "required": [
        "channelPriority",
        "channelName",
        "channelDetails"
      ],
      "additionalProperties": false
    },
    "ProcessTypeCertificationLevels": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "communication_sent",
          "communication_received",
          "explicit_acceptance"
        ]
      },
      "minItems": 1
    },
    "RejectReason": {
      "title": "rejectReason",
      "type": "object",
      "description": "Reject reason",
      "properties": {
        "defaultReason": {
          "type": "string",
          "description": "Default reason"
        }
      },
      "additionalProperties": {
        "description": "Key-value pairs for reason localization: keys are languages in ISO 639-2 Code (alpha-3) format, like 'ita', 'eng'",
        "type": "string"
      },
      "required": [
        "defaultReason"
      ]
    },
    "ReminderConfiguration": {
      "title": "ReminderConfiguration",
      "type": "object",
      "properties": {
        "daysUntilReminder": {
          "type": "integer",
          "minimum": 1,
          "description": "Number of days after which a reminder is sent"
        },
        "channelName": {
          "type": "string",
          "enum": [
            "email",
            "sms",
            "whatsapp"
          ],
          "description": "Reminder channel"
        }
      },
      "required": [
        "daysUntilReminder",
        "channelName"
      ],
      "additionalProperties": false
    },
    "SendingPolicy": {
      "title": "SendingPolicy",
      "type": "object",
      "description": "Controls retry scheduling. If numberOfRetries is greater than 1, frequency must be > 0.",
      "properties": {
        "numberOfRetries": {
          "type": "integer",
          "minimum": 1,
          "maximum": 5,
          "description": "Number of attempts (including first try)"
        },
        "frequency": {
          "type": "integer",
          "minimum": 0,
          "description": "Delay between retries (unit defined by backend; 0 allowed only when numberOfRetries=1)"
        },
        "timeout": {
          "type": "integer",
          "minimum": 1,
          "description": "Overall timeout before the dispatch expires (unit defined by backend)"
        }
      },
      "required": [
        "numberOfRetries",
        "frequency",
        "timeout"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "numberOfRetries": {
                "minimum": 2
              }
            },
            "required": [
              "numberOfRetries"
            ]
          },
          "then": {
            "properties": {
              "frequency": {
                "minimum": 1
              }
            }
          }
        }
      ]
    },
    "emailChannel": {
      "title": "emailChannel",
      "type": "object",
      "properties": {
        "subject": {
          "type": "string",
          "maxLength": 200,
          "description": "Message subject"
        },
        "body": {
          "type": "string",
          "description": "Message body (HTML supported for email/external)"
        }
      },
      "required": [
        "subject",
        "body"
      ],
      "additionalProperties": false
    },
    "externalChannel": {
      "title": "externalChannel",
      "type": "object",
      "properties": {
        "subject": {
          "type": "string",
          "maxLength": 200,
          "description": "Message subject"
        },
        "body": {
          "type": "string",
          "description": "Message body (HTML supported for email/external)"
        }
      },
      "required": [
        "subject",
        "body"
      ],
      "additionalProperties": false
    },
    "smsChannel": {
      "title": "smsChannel",
      "type": "object",
      "properties": {
        "body": {
          "type": "string",
          "description": "Message body"
        }
      },
      "required": [
        "body"
      ],
      "additionalProperties": false
    },
    "whatsappChannel": {
      "title": "whatsappChannel",
      "type": "object",
      "properties": {
        "body": {
          "type": "string",
          "description": "Message body"
        }
      },
      "required": [
        "body"
      ],
      "additionalProperties": false
    }
  }
}