{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.modernedi.com/integration-api/configuration-partner.schema.json",
  "title": "ModernEDI partner configuration",
  "description": "Portable desired state for one active trading partner.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "apiVersion",
    "kind",
    "metadata",
    "spec"
  ],
  "properties": {
    "apiVersion": {
      "$ref": "#/$defs/ConfigurationDocumentApiVersion"
    },
    "kind": {
      "type": "string",
      "enum": [
        "Partner"
      ]
    },
    "metadata": {
      "$ref": "#/$defs/ConfigurationResourceMetadata"
    },
    "spec": {
      "$ref": "#/$defs/ConfigurationPartnerSpec"
    }
  },
  "$defs": {
    "ConfigurationDocumentApiVersion": {
      "type": "string",
      "enum": [
        "modernedi.com/v1"
      ],
      "description": "Version of the portable configuration document contract used by export, planning, and apply."
    },
    "ConfigurationResourceMetadata": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "key"
      ],
      "properties": {
        "key": {
          "type": "string",
          "format": "uuid",
          "description": "Stable portable identity for this resource."
        }
      }
    },
    "ConfigurationPartnerSpec": {
      "description": "Complete persisted partner configuration. It replaces `as2ConnectionId` with a portable `as2ConnectionKey` and includes advanced runtime compatibility settings that participate in workspace configuration.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "as2ConnectionKey",
        "x12",
        "ediSupportEmail",
        "carbonCopyOnly",
        "implementationAcknowledgmentEnabled",
        "unmappedInboundPolicy",
        "signingCertificateSlot",
        "supportsNewlineAfterSegmentTerminator",
        "overrideUserAgentString",
        "overrideSeparatorSet",
        "messageTypeGsVersionOverrides"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "description": "Unique partner display name in this workspace."
        },
        "as2ConnectionKey": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "Portable key of the referenced AS2 connection, or `null` for a detached map-authoring draft."
        },
        "x12": {
          "description": "Current production and optional test X12 identities. Detached drafts may contain incomplete authoring values.",
          "anyOf": [
            {
              "$ref": "#/$defs/PartnerX12Identities"
            },
            {
              "$ref": "#/$defs/PartnerDraftX12Identities"
            }
          ]
        },
        "ediSupportEmail": {
          "type": "string",
          "description": "Partner EDI support address, or an empty string when unavailable."
        },
        "carbonCopyOnly": {
          "type": "boolean"
        },
        "implementationAcknowledgmentEnabled": {
          "type": "boolean",
          "description": "Whether eligible inbound documents receive a 999 instead of a 997."
        },
        "unmappedInboundPolicy": {
          "type": "string",
          "enum": [
            "MAPPED_ONLY",
            "PASSTHROUGH_RAW_X12"
          ]
        },
        "signingCertificateSlot": {
          "type": "string",
          "enum": [
            "active",
            "next"
          ]
        },
        "supportsNewlineAfterSegmentTerminator": {
          "type": "boolean"
        },
        "overrideUserAgentString": {
          "type": [
            "string",
            "null"
          ],
          "description": "Optional AS2 HTTP User-Agent compatibility override."
        },
        "overrideSeparatorSet": {
          "description": "Optional X12 separator override, or `null` to use runtime defaults.",
          "oneOf": [
            {
              "$ref": "#/$defs/ConfigurationPartnerSeparatorSet"
            },
            {
              "type": [
                "object",
                "null"
              ],
              "enum": [
                null
              ]
            }
          ]
        },
        "messageTypeGsVersionOverrides": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          },
          "description": "Closed runtime compatibility map from supported X12 message-type names to GS08 version overrides. An empty object means no overrides."
        }
      }
    },
    "PartnerX12Identities": {
      "type": "object",
      "required": [
        "production",
        "test"
      ],
      "description": "Production is always configured. Test is `null` for a production-only partner.",
      "properties": {
        "production": {
          "description": "Complete production X12 sender identity for this connected partner.",
          "$ref": "#/$defs/PartnerX12Identity"
        },
        "test": {
          "description": "Complete test X12 sender identity, or `null` when this partner has no separate test identity.",
          "oneOf": [
            {
              "$ref": "#/$defs/PartnerX12Identity"
            },
            {
              "type": [
                "object",
                "null"
              ],
              "enum": [
                null
              ]
            }
          ]
        }
      }
    },
    "PartnerX12Identity": {
      "type": "object",
      "required": [
        "isaQualifier",
        "isaId",
        "gsId"
      ],
      "properties": {
        "isaQualifier": {
          "type": "string",
          "minLength": 2,
          "maxLength": 2,
          "description": "ISA qualifier ModernEDI expects for this partner in the selected environment. Connected partners always use exactly 2 characters; detached draft values may be incomplete.",
          "example": "ZZ"
        },
        "isaId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 15,
          "description": "ISA id ModernEDI expects for this partner in the selected environment. Connected partners always use between 1 and 15 characters inclusive; detached draft values may be incomplete.",
          "example": "CUSTOMERONE"
        },
        "gsId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 15,
          "description": "GS sender or receiver id configured for this partner in the selected environment. Connected partners always use between 1 and 15 characters inclusive; detached draft values may be incomplete.",
          "example": "CUSTOMERONE"
        }
      }
    },
    "PartnerDraftX12Identities": {
      "type": "object",
      "description": "Resolved authoring values returned for a detached partner draft. Production fields may remain incomplete until an AS2 connection is attached. Test is `null` when no test identity has been entered.",
      "required": [
        "production",
        "test"
      ],
      "properties": {
        "production": {
          "description": "Current production authoring values, which may be incomplete until transport is attached.",
          "$ref": "#/$defs/PartnerDraftX12Identity"
        },
        "test": {
          "description": "Current test authoring values, or `null` when no test identity has been entered.",
          "oneOf": [
            {
              "$ref": "#/$defs/PartnerDraftX12Identity"
            },
            {
              "type": [
                "object",
                "null"
              ],
              "enum": [
                null
              ]
            }
          ]
        }
      }
    },
    "PartnerDraftX12Identity": {
      "type": "object",
      "required": [
        "isaQualifier",
        "isaId",
        "gsId"
      ],
      "properties": {
        "isaQualifier": {
          "type": "string",
          "description": "Draft ISA qualifier. Attaching an AS2 connection requires exactly 2 characters."
        },
        "isaId": {
          "type": "string",
          "description": "Draft ISA id. Attaching an AS2 connection requires between 1 and 15 characters inclusive."
        },
        "gsId": {
          "type": "string",
          "description": "Draft GS id. Attaching an AS2 connection requires between 1 and 15 characters inclusive."
        }
      }
    },
    "ConfigurationPartnerSeparatorSet": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "elementSeparator",
        "subElementSeparator",
        "segmentTerminator",
        "repetitionSeparator"
      ],
      "properties": {
        "elementSeparator": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1
        },
        "subElementSeparator": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1
        },
        "segmentTerminator": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1
        },
        "repetitionSeparator": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1,
          "maxLength": 1,
          "description": "Repetition separator, or `null` when the selected X12 version does not use one."
        }
      }
    }
  }
}
