{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "title": "Microsite Template Schema",
  "description": "Defines the schema for a microsite auto-setup template",
  "type": "object",
  "required": [
    "key",
    "name",
    "description",
    "hostedPortalConfig",
    "managedIdentityConfig",
    "emails",
    "registrationForms",
    "layouts",
    "pages"
  ],
  "additionalProperties": false,
  "properties": {
    "key": {
      "type": "string",
      "description": "A unique identifier for this template"
    },
    "name": {
      "type": "string",
      "description": "The name of this template"
    },
    "description": {
      "type": "string",
      "description": "A brief description of this template"
    },
    "hostedPortalConfig": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "Hosted Portal Config",
      "type": "object",
      "required": [
        "enabled"
      ],
      "additionalProperties": false,
      "properties": {
        "enabled": {
          "title": "Enabled",
          "description": "Enable the hosted portal",
          "default": false,
          "type": "boolean"
        },
        "domain": {
          "title": "Domain",
          "description": "The domain the hosted portal is hosted on",
          "type": "string"
        },
        "headHtml": {
          "title": "Head HTML",
          "description": "The HTML to be injected into the <head> element of the hosted portal",
          "type": "string"
        },
        "brandingConfig": {
          "type": "object",
          "title": "Branding Config"
        },
        "widgetKey": {
          "title": "Widget Key",
          "description": "The widget key of the hosted portal",
          "type": "string"
        },
        "dependencies": {
          "type": "array",
          "title": "Dependencies",
          "description": "A list of NPM resources to load into the widget",
          "items": {
            "type": "object",
            "properties": {
              "package": {
                "type": "string",
                "description": "An NPM package name or scoped package"
              },
              "version": {
                "type": "string",
                "description": "An NPM version string, such as Patch releases: 1.0 or 1.0.x or ~1.0.4 Minor releases: 1 or 1.x or ^1.0.4 Major releases: * or x"
              },
              "filePath": {
                "type": "string",
                "description": "The path to a resource in the specified package"
              }
            },
            "required": [
              "version",
              "package"
            ],
            "additionalProperties": false
          }
        },
        "notFoundUrlPath": {
          "type": "string",
          "title": "Not Found URL Path",
          "description": "The URL path for the 404 Not Found page"
        },
        "googleOAuthSdkClientId": {
          "type": "string",
          "title": "Google OAuth SDK Client ID",
          "description": "The Google OAuth SDK Client ID configured for the client"
        }
      }
    },
    "managedIdentityConfig": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "Managed Identity Config",
      "type": "object",
      "required": [
        "enabled"
      ],
      "additionalProperties": false,
      "properties": {
        "enabled": {
          "title": "Enabled",
          "description": "Enable managed identity",
          "type": "boolean",
          "default": false
        },
        "firebaseAuthTenantId": {
          "title": "Firebase Auth Tenant ID",
          "description": "The Google Identity tenant ID",
          "type": "string"
        },
        "resetPasswordEmailKey": {
          "title": "Reset Password Email Key",
          "description": "The email key used for reset password emails",
          "type": "string"
        },
        "verifyEmailEmailKey": {
          "title": "Verify Email Email Key",
          "description": "The email key used for verification emails",
          "type": "string"
        },
        "idMethod": {
          "title": "ID Method",
          "description": "The source of id and accountId for new users, email or firebase uid",
          "enum": [
            "EMAIL",
            "UID",
            "HASHED_EMAIL"
          ],
          "type": "string"
        },
        "idPrefix": {
          "title": "ID Prefix",
          "description": "The prefix added to new users' id and accountId",
          "default": "",
          "type": "string"
        },
        "disallowNewUsers": {
          "title": "Disallow New Users",
          "description": "Prevent new users from being created via managed identity. Only works with 'EMAIL' ID Method",
          "default": false,
          "type": "boolean"
        },
        "managedIdentityHandlerUrl": {
          "title": "Managed Identity Handler URL",
          "description": "The URL of a handler for external processing of registration, authentication, and session data",
          "type": "string"
        },
        "userUpsertTransformer": {
          "title": "User Upsert Transformer",
          "description": "A JSONata expression for transforming registration form data into a user upsert body",
          "type": "string"
        }
      }
    },
    "tenantSettings": {
      "type": "object",
      "properties": {
        "usTaxNotificationEmailKey": {
          "type": "string"
        }
      }
    },
    "emails": {
      "type": "array",
      "description": "The emails to be created by this template",
      "items": {
        "type": "object",
        "required": [
          "key",
          "values"
        ],
        "additionalProperties": false,
        "properties": {
          "key": {
            "type": "string",
            "description": "The global email key"
          },
          "values": {
            "$schema": "http://json-schema.org/draft-06/schema",
            "title": "HTML Email Template Schema",
            "description": "Defines the customization points available in an HTML body email template.",
            "type": "object",
            "additionalProperties": false,
            "required": [
              "meta",
              "htmlContent"
            ],
            "properties": {
              "meta": {
                "type": "object",
                "title": "Email",
                "required": [
                  "fromName",
                  "fromAddress",
                  "subject"
                ],
                "additionalProperties": false,
                "properties": {
                  "fromName": {
                    "type": "string",
                    "title": "From Name",
                    "default": "My Company",
                    "propertyOrder": 1,
                    "minLength": 1,
                    "options": {
                      "validate": [
                        "handlebars"
                      ]
                    }
                  },
                  "fromAddress": {
                    "type": "string",
                    "title": "From Address",
                    "default": "company@example.com",
                    "propertyOrder": 2,
                    "minLength": 5,
                    "options": {
                      "validate": [
                        "handlebars"
                      ]
                    }
                  },
                  "subject": {
                    "type": "string",
                    "title": "Subject",
                    "propertyOrder": 3,
                    "minLength": 1,
                    "options": {
                      "validate": [
                        "handlebars"
                      ],
                      "input_height": "50px"
                    }
                  },
                  "bcc": {
                    "type": "array",
                    "title": "BCC",
                    "items": {
                      "type": "string",
                      "minLength": 5
                    }
                  }
                }
              },
              "htmlContent": {
                "type": "string",
                "title": "HTML Content",
                "description": "Raw HTML content that can use {{mergeTags}} from handlebars"
              },
              "jsonContent": {
                "type": "object",
                "title": "JSON Content",
                "description": "The JSON content for the email editor"
              }
            }
          }
        }
      }
    },
    "registrationForms": {
      "type": "array",
      "description": "The registration forms to be created by this template",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key",
          "name"
        ],
        "properties": {
          "key": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "globalConfig": {
            "type": "object"
          }
        }
      }
    },
    "layouts": {
      "type": "array",
      "description": "The layouts to be created by this template",
      "items": {
        "type": "object",
        "required": [
          "key",
          "name"
        ],
        "additionalProperties": false,
        "properties": {
          "key": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "parentKey": {
            "type": "string"
          },
          "values": {
            "$schema": "http://json-schema.org/draft-07/schema#",
            "title": "Microsite Layout Config Values",
            "type": "object",
            "required": [
              "html"
            ],
            "additionalProperties": false,
            "properties": {
              "html": {
                "title": "HTML",
                "description": "The HTML template",
                "type": "string"
              }
            }
          }
        }
      }
    },
    "pages": {
      "type": "array",
      "description": "The pages to be created by this template",
      "items": {
        "type": "object",
        "required": [
          "key",
          "layoutKey",
          "urlPath",
          "allowedUsers"
        ],
        "additionalProperties": false,
        "properties": {
          "key": {
            "type": "string"
          },
          "layoutKey": {
            "type": "string"
          },
          "urlPath": {
            "type": "string"
          },
          "allowedUsers": {
            "type": "string"
          },
          "disallowedUrlPath": {
            "type": "string"
          },
          "values": {
            "$schema": "http://json-schema.org/draft-07/schema#",
            "title": "Microsite Page Config Values",
            "type": "object",
            "required": [
              "html",
              "title"
            ],
            "additionalProperties": false,
            "properties": {
              "title": {
                "title": "Title",
                "description": "The HTML page title",
                "type": "string"
              },
              "description": {
                "title": "Description",
                "description": "The HTML page description",
                "type": "string"
              },
              "html": {
                "title": "HTML",
                "description": "The HTML template",
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}