{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/certifyos/main/json-schema/certifyos-event-email-settings-request-schema.json",
  "title": "EventEmailSettingsRequest",
  "description": "Request body for POST or PUT /organizations/{organizationId}/event-email-settings/{context}/{mode}. Context and mode are specified in the URL path, not in this body. Submitting this creates the settings record for that context+mode if none exists, or fully replaces it if one does.",
  "x-generated": "2026-10-20",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/certifyos-event-email-settings-api-openapi.yml#/components/schemas/EventEmailSettingsRequest",
  "type": "object",
  "required": [
    "recipientPreferences",
    "typeSettings"
  ],
  "properties": {
    "recipientPreferences": {
      "$ref": "#/$defs/EventEmailRecipientPreferencesDto",
      "type": "object",
      "description": "Recipient preference flags for this context. Persisted at the context level (not per-mode): saving this value here also changes it for the sibling mode of the same context."
    },
    "ccEmail": {
      "type": "string",
      "description": "CC email address applied to event emails for this context+mode. Stored at the mode level here — distinct from the context-level ccEmail settable via POST /{context}/cc-email, which takes priority on read when both are set. Must be a valid email address format (enforced by validation); omit to leave unset."
    },
    "typeSettings": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/EventEmailTypeSettingsDto"
      },
      "description": "One entry per event email type; should cover all six type values (initiated, approved, denied, cancelled, psvReady, inProgress), though this is not enforced by the server. Any entry with enabled: true must supply a non-blank template.subject and template.bodyHtml, or the request is rejected with 400."
    }
  },
  "$defs": {
    "EventEmailRecipientPreferencesDto": {
      "type": "object",
      "description": "Boolean flags controlling which recipient types receive event emails for a context.",
      "properties": {
        "primaryEmail": {
          "type": "boolean",
          "description": "true to send event emails to the practitioner's or facility's primary email on file; false or null to skip this recipient."
        },
        "caqhPrimaryEmail": {
          "type": "boolean",
          "description": "true to send event emails to the CAQH-sourced primary email on file; false or null to skip this recipient."
        },
        "credentialingPrimaryContact": {
          "type": "boolean",
          "description": "true to send event emails to the credentialing workflow's primary contact; false or null to skip this recipient."
        },
        "credentialingOfficeManager": {
          "type": "boolean",
          "description": "true to send event emails to the office manager on the credentialing workflow; false or null to skip this recipient."
        }
      }
    },
    "EventEmailTemplateDto": {
      "type": "object",
      "required": [
        "subject",
        "bodyHtml"
      ],
      "description": "Subject and body content for one event email type's template.",
      "properties": {
        "subject": {
          "type": "string",
          "description": "Email subject line. Required and must be non-blank when the parent typeSettings entry has enabled: true."
        },
        "bodyHtml": {
          "type": "string",
          "description": "Email body as HTML markup. Required and must be non-blank when the parent typeSettings entry has enabled: true."
        }
      }
    },
    "EventEmailTypeSettingsDto": {
      "type": "object",
      "required": [
        "type",
        "template",
        "enabled"
      ],
      "description": "Template and enablement settings for one event email type within a mode.",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "initiated",
            "approved",
            "denied",
            "cancelled",
            "psvReady",
            "inProgress"
          ],
          "pattern": "\\S",
          "description": "Which workflow event this entry configures: \"initiated\" (workflow started), \"approved\" (credentialing/recredentialing approved), \"denied\" (application denied), \"cancelled\" (workflow cancelled), \"psvReady\" (primary source verification complete), \"inProgress\" (workflow in progress)."
        },
        "template": {
          "$ref": "#/$defs/EventEmailTemplateDto",
          "type": "object",
          "description": "Email subject/body template for this event type. Required (non-blank subject and bodyHtml) when enabled is true; the server rejects the save with 400 otherwise."
        },
        "enabled": {
          "type": "boolean",
          "description": "Whether an email is sent for this event type. When true, template.subject and template.bodyHtml must be non-blank."
        }
      }
    }
  }
}