{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "title": "go-proxy config file",
  "properties": {
    "autocert": {
      "title": "Autocert configuration",
      "type": "object",
      "properties": {
        "email": {
          "title": "ACME Email",
          "type": "string",
          "pattern": "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$",
          "patternErrorMessage": "Invalid email"
        },
        "domains": {
          "title": "Cert Domains",
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1
        },
        "cert_path": {
          "title": "path of cert file to load/store",
          "default": "certs/cert.crt",
          "markdownDescription": "default: `certs/cert.crt`",
          "type": "string"
        },
        "key_path": {
          "title": "path of key file to load/store",
          "default": "certs/priv.key",
          "markdownDescription": "default: `certs/priv.key`",
          "type": "string"
        },
        "provider": {
          "title": "DNS Challenge Provider",
          "default": "local",
          "type": "string",
          "enum": [
            "local",
            "cloudflare",
            "clouddns",
            "duckdns",
            "ovh"
          ]
        },
        "options": {
          "title": "Provider specific options",
          "type": "object"
        }
      },
      "allOf": [
        {
          "if": {
            "not": {
              "properties": {
                "provider": {
                  "const": "local"
                }
              }
            }
          },
          "then": {
            "required": [
              "email",
              "domains",
              "provider",
              "options"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "provider": {
                "const": "cloudflare"
              }
            }
          },
          "then": {
            "properties": {
              "options": {
                "required": [
                  "auth_token"
                ],
                "additionalProperties": false,
                "properties": {
                  "auth_token": {
                    "description": "Cloudflare API Token with Zone Scope",
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "provider": {
                "const": "clouddns"
              }
            }
          },
          "then": {
            "properties": {
              "options": {
                "required": [
                  "client_id",
                  "email",
                  "password"
                ],
                "additionalProperties": false,
                "properties": {
                  "client_id": {
                    "description": "CloudDNS Client ID",
                    "type": "string"
                  },
                  "email": {
                    "description": "CloudDNS Email",
                    "type": "string"
                  },
                  "password": {
                    "description": "CloudDNS Password",
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "provider": {
                "const": "duckdns"
              }
            }
          },
          "then": {
            "properties": {
              "options": {
                "required": [
                  "token"
                ],
                "additionalProperties": false,
                "properties": {
                  "token": {
                    "description": "DuckDNS Token",
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "provider": {
                "const": "ovh"
              }
            }
          },
          "then": {
            "properties": {
              "options": {
                "required": [
                  "application_secret",
                  "consumer_key"
                ],
                "additionalProperties": false,
                "oneOf": [
                  {
                    "required": [
                      "application_key"
                    ]
                  },
                  {
                    "required": [
                      "oauth2_config"
                    ]
                  }
                ],
                "properties": {
                  "api_endpoint": {
                    "description": "OVH API endpoint",
                    "default": "ovh-eu",
                    "anyOf": [
                      {
                        "enum": [
                          "ovh-eu",
                          "ovh-ca",
                          "ovh-us",
                          "kimsufi-eu",
                          "kimsufi-ca",
                          "soyoustart-eu",
                          "soyoustart-ca"
                        ]
                      },
                      {
                        "type": "string",
                        "format": "uri"
                      }
                    ]
                  },
                  "application_secret": {
                    "description": "OVH Application Secret",
                    "type": "string"
                  },
                  "consumer_key": {
                    "description": "OVH Consumer Key",
                    "type": "string"
                  },
                  "application_key": {
                    "description": "OVH Application Key",
                    "type": "string"
                  },
                  "oauth2_config": {
                    "description": "OVH OAuth2 config",
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "client_id": {
                        "description": "OVH Client ID",
                        "type": "string"
                      },
                      "client_secret": {
                        "description": "OVH Client Secret",
                        "type": "string"
                      }
                    },
                    "required": [
                      "client_id",
                      "client_secret"
                    ]
                  }
                }
              }
            }
          }
        }
      ]
    },
    "providers": {
      "title": "Proxy providers configuration",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "include": {
          "title": "Proxy providers configuration files",
          "description": "relative path to 'config'",
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9_-]+\\.(yml|yaml)$",
            "patternErrorMessage": "Invalid file name"
          }
        },
        "docker": {
          "title": "Docker provider configuration",
          "description": "docker clients (name-address pairs)",
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9-_]+$": {
              "type": "string",
              "examples": [
                "unix:///var/run/docker.sock",
                "tcp://127.0.0.1:2375",
                "ssh://user@host:port"
              ],
              "oneOf": [
                {
                  "const": "$DOCKER_HOST",
                  "description": "Use DOCKER_HOST environment variable"
                },
                {
                  "pattern": "^unix://.+$",
                  "description": "A Unix socket for local Docker communication."
                },
                {
                  "pattern": "^ssh://.+$",
                  "description": "An SSH connection to a remote Docker host."
                },
                {
                  "pattern": "^fd://.+$",
                  "description": "A file descriptor for Docker communication."
                },
                {
                  "pattern": "^tcp://.+$",
                  "description": "A TCP connection to a remote Docker host."
                }
              ]
            }
          }
        }
      }
    },
    "match_domains": {
      "title": "Domains to match",
      "type": "array",
      "items": {
        "type": "string"
      },
      "minItems": 1
    },
    "timeout_shutdown": {
      "title": "Shutdown timeout (in seconds)",
      "type": "integer",
      "minimum": 0
    },
    "redirect_to_https": {
      "title": "Redirect to HTTPS on HTTP requests",
      "type": "boolean"
    }
  },
  "additionalProperties": false,
  "required": [
    "providers"
  ]
}