{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "definitions": {
    "contexts": {
      "type": "object",
      "patternProperties": {
        "^[A-Za-z0-9_]+$": {
          "$ref": "#/definitions/context"
        }
      }
    },
    "context": {
      "if": {
        "properties": {
          "connectionString": {
            "pattern": "sqlite://.+"
          }
        }
      },
      "then": {
        "properties": {
          "module": {
            "type": "string"
          },
          "connectionString": {
            "type": "string"
          },
          "schemaLocation": {
            "type": "string"
          },
          "schemaName": {
            "type": "string"
          },
          "migrationLocation": {
            "type": "string"
          },
          "authorization": {
            "$ref": "#/definitions/authorization"
          },
          "options": {
            "properties": {
              "dropIfExists": {
                "type": "boolean"
              }
            },
            "additionalProperties": false
          }
        },
        "required": ["connectionString"],
        "additionalProperties": false
      },
      "else": {
        "if": {
          "properties": {
            "connectionString": {
              "pattern": "postgres://.+"
            }
          }
        },
        "then": {
          "properties": {
            "module": {
              "type": "string"
            },
            "connectionString": {
              "type": "string"
            },
            "schemaLocation": {
              "type": "string"
            },
            "schemaName": {
              "type": "string"
            },
            "migrationLocation": {
              "type": "string"
            },
            "authorization": {
              "$ref": "#/definitions/authorization"
            },
            "options": {
              "properties": {
                "createIfNotExists": {
                  "type": "boolean"
                }
              },
              "additionalProperties": false
            }
          },
          "required": ["connectionString"],
          "additionalProperties": false
        },
        "else": {
          "if": {
            "properties": {
              "connectionString": {
                "pattern": "(http|https)://.+"
              }
            }
          },
          "then": {
            "properties": {
              "module": {
                "type": "string"
              },
              "connectionString": {
                "type": "string"
              },
              "schemaLocation": {
                "type": "string"
              },
              "schemaName": {
                "type": "string"
              },
              "migrationLocation": {
                "type": "string"
              }
            },
            "required": ["connectionString"],
            "additionalProperties": false
          },
          "else": {
            "additionalProperties": false
          }
        }
      }
    },
    "authorization": {
      "type": "object",
      "properties": {
        "providers": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/authorizationProvider"
          }
        },
        "tokens": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/authorizationToken"
          }
        },
        "userPools": {
          "type": "object",
          "patternProperties": {
            "^[A-Za-z0-9_]+$": {
              "$ref": "#/definitions/authorizationUserPool"
            }
          }
        },
        "disableRules": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "authorizationUserPool": {
      "type": "object",
      "properties": {
        "cors": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "roles": {
          "type": "object",
          "patternProperties": {
            "^[A-Za-z0-9_]+$": {
              "$ref": "#/definitions/authorizationUserPoolRole"
            }
          }
        },
        "users": {
          "type": "object",
          "patternProperties": {
            "^[A-Za-z0-9_]+$": {
              "$ref": "#/definitions/authorizationUserPoolUser"
            }
          }
        },
        "name": {
          "type": "string"
        },
        "accessTokenExpiresIn": {
          "type": "number",
          "default": 600,
          "$comment": "in seconds"
        },
        "algorithm": {
          "type": "string",
          "default": "RS256",
          "enum": ["RS256", "RS384", "RS512", "ES384", "ES512"]
        },
        "allowRegistration": {
          "type": "boolean",
          "default": true
        },
        "checkPasswordForBreach": {
          "type": "boolean",
          "default": false
        },
        "emailVerifyExpiresIn": {
          "type": "number",
          "default": 3600,
          "$comment": "in seconds"
        },
        "refreshRefreshExpiresIn": {
          "type": "number",
          "default": 3600,
          "$comment": "in seconds"
        }
      },
      "additionalProperties": false
    },
    "authorizationUserPoolRole": {
      "type": "object",
      "properties": {
        "description": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "authorizationUserPoolUser": {
      "type": "object",
      "properties": {
        "roles": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "phone": {
          "type": "string"
        },
        "phoneVerified": {
          "type": "boolean"
        },
        "email": {
          "type": "string"
        },
        "emailVerified": {
          "type": "boolean"
        },
        "password": {
          "type": "string"
        },
        "disabled": {
          "type": "boolean"
        }
      },
      "additionalProperties": false,
      "required": ["password"]
    },
    "authorizationProvider": {
      "type": "object",
      "properties": {
        "uri": {
          "type": "string"
        },
        "issuer": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": ["issuer", "uri"]
    },
    "authorizationToken": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "uri": {
          "type": "string"
        },
        "issuer": {
          "type": "string"
        }
      }
    }
  },
  "properties": {
    "context": {
      "$ref": "#/definitions/contexts"
    }
  },
  "required": [
    "context"
  ]
}
