{
  "$schema": "https://json-schema.org/draft/2020-12/schema#",
  "$id": "https://schema.mp.microsoft.com/schema/customer-leads/2022-03-01-preview3",
  "title": "CustomerLeads",
  "description": "Connect a CRM system to receive customer leads",
  "allOf": [
    {
      "$ref": "https://schema.mp.microsoft.com/schema/resource/2022-03-01-preview2"
    },
    {
      "type": "object",
      "properties": {
        "product": {
          "$ref": "https://schema.mp.microsoft.com/schema/resource-reference/2022-03-01-preview2"
        },
        "leadDestination": {
          "enum": [
            "none",
            "blob",
            "dynamics",
            "email",
            "httpsEndpoint",
            "marketo",
            "salesforce",
            "table"
          ]
        },
        "blobLeadConfiguration": {
          "$ref": "#/$defs/blobLeadConfiguration"
        },
        "dynamicsLeadConfiguration": {
          "$ref": "#/$defs/dynamicsLeadConfiguration"
        },
        "emailLeadConfiguration": {
          "$ref": "#/$defs/emailLeadConfiguration"
        },
        "httpsEndpointLeadConfiguration": {
          "$ref": "#/$defs/httpsEndpointLeadConfiguration"
        },
        "marketoLeadConfiguration": {
          "$ref": "#/$defs/marketoLeadConfiguration"
        },
        "salesforceLeadConfiguration": {
          "$ref": "#/$defs/salesforceLeadConfiguration"
        },
        "tableLeadConfiguration": {
          "$ref": "#/$defs/tableLeadConfiguration"
        }
      },
      "required": [
        "product",
        "leadDestination"
      ]
    },
    {
      "oneOf": [
        {
          "properties": {
            "leadDestination": {
              "const": "none"
            }
          },
          "not": {
            "required": [
              "blobLeadConfiguration",
              "dynamicsLeadConfiguration",
              "emailLeadConfiguration",
              "httpsEndpointLeadConfiguration",
              "marketoLeadConfiguration",
              "salesforceLeadConfiguration",
              "tableLeadConfiguration"
            ]
          }
        },
        {
          "properties": {
            "leadDestination": {
              "const": "blob"
            }
          },
          "required": [
            "blobLeadConfiguration"
          ],
          "not": {
            "required": [
              "dynamicsLeadConfiguration",
              "emailLeadConfiguration",
              "httpsEndpointLeadConfiguration",
              "marketoLeadConfiguration",
              "salesforceLeadConfiguration",
              "tableLeadConfiguration"
            ]
          }
        },
        {
          "properties": {
            "leadDestination": {
              "const": "dynamics"
            }
          },
          "required": [
            "dynamicsLeadConfiguration"
          ],
          "not": {
            "required": [
              "blobLeadConfiguration",
              "emailLeadConfiguration",
              "httpsEndpointLeadConfiguration",
              "marketoLeadConfiguration",
              "salesforceLeadConfiguration",
              "tableLeadConfiguration"
            ]
          }
        },
        {
          "properties": {
            "leadDestination": {
              "const": "email"
            }
          },
          "required": [
            "emailLeadConfiguration"
          ],
          "not": {
            "required": [
              "blobLeadConfiguration",
              "dynamicsLeadConfiguration",
              "httpsEndpointLeadConfiguration",
              "marketoLeadConfiguration",
              "salesforceLeadConfiguration",
              "tableLeadConfiguration"
            ]
          }
        },
        {
          "properties": {
            "leadDestination": {
              "const": "httpsEndpoint"
            }
          },
          "required": [
            "httpsEndpointLeadConfiguration"
          ],
          "not": {
            "required": [
              "blobLeadConfiguration",
              "dynamicsLeadConfiguration",
              "emailLeadConfiguration",
              "marketoLeadConfiguration",
              "salesforceLeadConfiguration",
              "tableLeadConfiguration"
            ]
          }
        },
        {
          "properties": {
            "leadDestination": {
              "const": "marketo"
            }
          },
          "required": [
            "marketoLeadConfiguration"
          ],
          "not": {
            "required": [
              "blobLeadConfiguration",
              "dynamicsLeadConfiguration",
              "emailLeadConfiguration",
              "httpsEndpointLeadConfiguration",
              "salesforceLeadConfiguration",
              "tableLeadConfiguration"
            ]
          }
        },
        {
          "properties": {
            "leadDestination": {
              "const": "salesforce"
            }
          },
          "required": [
            "salesforceLeadConfiguration"
          ],
          "not": {
            "required": [
              "blobLeadConfiguration",
              "dynamicsLeadConfiguration",
              "emailLeadConfiguration",
              "httpsEndpointLeadConfiguration",
              "marketoLeadConfiguration",
              "tableLeadConfiguration"
            ]
          }
        },
        {
          "properties": {
            "leadDestination": {
              "const": "table"
            }
          },
          "required": [
            "tableLeadConfiguration"
          ],
          "not": {
            "required": [
              "blobLeadConfiguration",
              "dynamicsLeadConfiguration",
              "emailLeadConfiguration",
              "httpsEndpointLeadConfiguration",
              "marketoLeadConfiguration",
              "salesforceLeadConfiguration"
            ]
          }
        }
      ]
    }
  ],
  "$defs": {
    "https://schema.mp.microsoft.com/schema/resource/2022-03-01-preview2": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/resource/2022-03-01-preview2",
      "$comment": "This schema is extended by a resource type schema. We allow additional properties to enable that",
      "type": "object",
      "properties": {
        "resourceName": {
          "type": "string",
          "minLength": 1,
          "maxLength": 50
        },
        "id": {
          "$ref": "https://schema.mp.microsoft.com/schema/durable-id/2022-03-01-preview2"
        },
        "validations": {
          "type": "array",
          "items": {
            "$ref": "https://schema.mp.microsoft.com/schema/validation/2022-03-01-preview2"
          },
          "readonly": true
        }
      },
      "required": [
        "$schema"
      ],
      "additionalProperties": true
    },
    "https://schema.mp.microsoft.com/schema/resource-reference/2022-03-01-preview2": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/resource-reference/2022-03-01-preview2",
      "oneOf": [
        {
          "$ref": "https://schema.mp.microsoft.com/schema/durable-id/2022-03-01-preview2"
        },
        {
          "type": "object",
          "properties": {
            "externalId": {
              "description": "ExternalId for product and plan references. Property reference must be named product or plan.",
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-_]{2,49}$",
              "minLength": 3,
              "maxLength": 50,
              "$example": {
                "plan": {
                  "externalId": "customerNamedPlan123"
                }
              }
            }
          },
          "required": [
            "externalId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "resourceName": {
              "description": "Resource Name that can be referenced using this value by another resource.",
              "type": "string",
              "pattern": "^[a-zA-Z0-9-_]\u002B$",
              "minLength": 1,
              "maxLength": 50,
              "$example": {
                "plan": {
                  "resourceName": "resourcePlan1"
                }
              }
            }
          },
          "required": [
            "resourceName"
          ]
        }
      ]
    },
    "https://schema.mp.microsoft.com/schema/durable-id/2022-03-01-preview2": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/durable-id/2022-03-01-preview2",
      "description": "A durable-id to an existing resource.",
      "type": "string",
      "pattern": "^[a-z](-?[a-z0-9]\u002B)*/[a-z0-9-]\u002B(\\/?[a-z0-9-])*$"
    },
    "https://schema.mp.microsoft.com/schema/validation/2022-03-01-preview2": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/validation/2022-03-01-preview2",
      "allOf": [
        {
          "$ref": "https://schema.mp.microsoft.com/schema/inner-error/2022-03-01-preview2"
        },
        {
          "properties": {
            "$schema": {
              "$ref": "https://schema.mp.microsoft.com/schema/schema-uri/2022-03-01-preview2"
            },
            "level": {
              "type": "string",
              "enum": [
                "informational",
                "warning"
              ]
            }
          },
          "required": [
            "level"
          ]
        }
      ]
    },
    "https://schema.mp.microsoft.com/schema/inner-error/2022-03-01-preview2": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/inner-error/2022-03-01-preview2",
      "type": "object",
      "properties": {
        "resourceId": {
          "$ref": "https://schema.mp.microsoft.com/schema/resource-reference/2022-03-01-preview2"
        },
        "code": {
          "type": "string",
          "readOnly": true,
          "enum": [
            "businessValidationError",
            "collectionLimitExceeded",
            "invalidId",
            "invalidEntityStatus",
            "invalidRequest",
            "invalidResource",
            "invalidState",
            "notDeployed",
            "notSupported",
            "operationCanceled",
            "productLocked",
            "resourceNotFound",
            "schemaValidationError"
          ]
        },
        "message": {
          "type": "string"
        },
        "details": {
          "type": "array",
          "items": {
            "$ref": "https://schema.mp.microsoft.com/schema/inner-error/2022-03-01-preview2"
          }
        }
      },
      "required": [
        "code"
      ]
    },
    "https://schema.mp.microsoft.com/schema/schema-uri/2022-03-01-preview2": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/schema-uri/2022-03-01-preview2",
      "title": "Product Ingestion schema uri",
      "type": "string",
      "pattern": "^https://(schema(-int)?\\.mp\\.microsoft\\.com)|(product-ingestion(-int)?\\.azureedge\\.net)/schema/[a-z][a-z0-9]\u002B(?:-[a-z0-9]\u002B)*/\\d{4}(?:-\\d\\d){2}(?:-dev|-preview\\d\u002B)?$"
    },
    "blobLeadConfiguration": {
      "type": "object",
      "properties": {
        "storageAccountConnectionString": {
          "oneOf": [
            {
              "type": "string",
              "pattern": "^DefaultEndpointsProtocol=https;AccountName=[a-z0-9]{3,24};AccountKey=[0-9a-zA-Z=\u002B/]*(;|;EndpointSuffix=(core\\.chinacloudapi\\.cn|core\\.cloudapi\\.de|core\\.usgovcloudapi\\.net|core\\.windows\\.net))?$"
            },
            {
              "$ref": "https://schema.mp.microsoft.com/schema/masked-secret/2022-03-01-preview2"
            }
          ]
        },
        "containerName": {
          "type": "string",
          "pattern": "^[a-z0-9](([a-z0-9\\-[^\\-])){1,61}[a-z0-9]$"
        }
      },
      "required": [
        "storageAccountConnectionString",
        "containerName"
      ]
    },
    "dynamicsLeadConfiguration": {
      "type": "object",
      "properties": {
        "instanceUrl": {
          "type": "string",
          "pattern": "^(http|https)://[a-zA-Z0-9/?$\u002B-~!@#%^\u0026*()_=\u0027.:[\\]@,;]\u002B$"
        },
        "authentication": {
          "enum": [
            "azureAD",
            "office365"
          ]
        },
        "username": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "password": {
          "oneOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 256,
              "not": {
                "$ref": "https://schema.mp.microsoft.com/schema/masked-secret/2022-03-01-preview2"
              }
            },
            {
              "$ref": "https://schema.mp.microsoft.com/schema/masked-secret/2022-03-01-preview2"
            }
          ]
        },
        "applicationId": {
          "type": "string",
          "format": "uuid"
        },
        "applicationKey": {
          "oneOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 2048,
              "not": {
                "$ref": "https://schema.mp.microsoft.com/schema/masked-secret/2022-03-01-preview2"
              }
            },
            {
              "$ref": "https://schema.mp.microsoft.com/schema/masked-secret/2022-03-01-preview2"
            }
          ]
        },
        "directoryId": {
          "type": "string",
          "format": "uuid"
        }
      },
      "required": [
        "instanceUrl",
        "authentication"
      ],
      "oneOf": [
        {
          "properties": {
            "authentication": {
              "const": "azureAD"
            }
          },
          "required": [
            "applicationId",
            "applicationKey",
            "directoryId"
          ],
          "not": {
            "required": [
              "username",
              "password"
            ]
          }
        },
        {
          "properties": {
            "authentication": {
              "const": "office365"
            }
          },
          "required": [
            "username",
            "password"
          ],
          "not": {
            "required": [
              "applicationId",
              "applicationKey",
              "directoryId"
            ]
          }
        }
      ]
    },
    "emailLeadConfiguration": {
      "type": "object",
      "properties": {
        "contactEmail": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "email"
          },
          "minItems": 1
        }
      },
      "required": [
        "contactEmail"
      ]
    },
    "httpsEndpointLeadConfiguration": {
      "type": "object",
      "properties": {
        "httpsEndpointUrl": {
          "type": "string",
          "pattern": "^https://[a-zA-Z0-9/?$\u002B-~!@#%^\u0026*()_=\u0027.:[\\]@,;]\u002B$"
        }
      },
      "required": [
        "httpsEndpointUrl"
      ]
    },
    "marketoLeadConfiguration": {
      "type": "object",
      "properties": {
        "munchkinId": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9]{3}-[a-zA-Z0-9]{3}-[a-zA-Z0-9]{3}$"
        },
        "formId": {
          "type": "string",
          "pattern": "^\\d{1,8}$"
        },
        "clientId": {
          "type": "string",
          "format": "uuid"
        },
        "clientSecret": {
          "oneOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 2048,
              "not": {
                "$ref": "https://schema.mp.microsoft.com/schema/masked-secret/2022-03-01-preview2"
              }
            },
            {
              "$ref": "https://schema.mp.microsoft.com/schema/masked-secret/2022-03-01-preview2"
            }
          ]
        }
      },
      "required": [
        "munchkinId",
        "formId",
        "clientId",
        "clientSecret"
      ]
    },
    "salesforceLeadConfiguration": {
      "type": "object",
      "properties": {
        "objectIdentifier": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9]{15}$"
        }
      },
      "required": [
        "objectIdentifier"
      ]
    },
    "tableLeadConfiguration": {
      "type": "object",
      "properties": {
        "storageAccountConnectionString": {
          "oneOf": [
            {
              "type": "string",
              "pattern": "^DefaultEndpointsProtocol=https;AccountName=[a-z0-9]{3,24};AccountKey=[0-9a-zA-Z=\u002B/]*(;|;EndpointSuffix=(core\\.chinacloudapi\\.cn|core\\.cloudapi\\.de|core\\.usgovcloudapi\\.net|core\\.windows\\.net))?$"
            },
            {
              "$ref": "https://schema.mp.microsoft.com/schema/masked-secret/2022-03-01-preview2"
            }
          ]
        }
      },
      "required": [
        "storageAccountConnectionString"
      ]
    }
  }
}