{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "FileConfig",
  "type": "object",
  "properties": {
    "jpm_hosts": {
      "type": "array",
      "default": [],
      "items": {
        "$ref": "#/$defs/Host"
      }
    },
    "proxy": {
      "description": "HTTP pool balancing and backend probes. Omitted fields inherit their startup settings.",
      "$ref": "#/$defs/ProxyConfig"
    },
    "routes": {
      "description": "Omitted or null inherits JAPKA_ROUTES and UPSTREAMS. An empty array clears all routes.",
      "type": [
        "array",
        "null"
      ],
      "items": {
        "$ref": "#/$defs/Route"
      }
    },
    "sites": {
      "description": "Host-specific static roots. Omission clears all named sites.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/Site"
      }
    },
    "tls": {
      "description": "Omitted or null inherits the startup TLS_CERT and TLS_KEY pair.",
      "anyOf": [
        {
          "$ref": "#/$defs/TlsConfig"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "additionalProperties": false,
  "$defs": {
    "Action": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "not_found"
            }
          },
          "additionalProperties": false,
          "required": [
            "type"
          ]
        },
        {
          "type": "object",
          "properties": {
            "preserve_path": {
              "type": "boolean"
            },
            "status": {
              "type": "integer",
              "format": "uint16",
              "maximum": 65535,
              "minimum": 0
            },
            "target": {
              "type": "string"
            },
            "type": {
              "type": "string",
              "const": "redirect"
            }
          },
          "additionalProperties": false,
          "required": [
            "type",
            "status",
            "target",
            "preserve_path"
          ]
        }
      ]
    },
    "Balance": {
      "type": "string",
      "enum": [
        "round_robin",
        "least_connections"
      ]
    },
    "Host": {
      "type": "object",
      "properties": {
        "action": {
          "anyOf": [
            {
              "$ref": "#/$defs/Action"
            },
            {
              "type": "null"
            }
          ]
        },
        "force_https": {
          "type": "boolean",
          "default": false
        },
        "host": {
          "type": "string"
        },
        "hsts": {
          "type": "boolean",
          "default": false
        },
        "hsts_subdomains": {
          "type": "boolean",
          "default": false
        },
        "tls": {
          "type": "boolean",
          "default": false
        }
      },
      "additionalProperties": false,
      "required": [
        "host"
      ]
    },
    "HostCertificate": {
      "type": "object",
      "properties": {
        "cert": {
          "type": "string"
        },
        "host": {
          "type": "string"
        },
        "key": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "host",
        "cert",
        "key"
      ]
    },
    "ProxyConfig": {
      "type": "object",
      "properties": {
        "balance": {
          "description": "HTTP balancing for every route. Omitted or null inherits JAPKA_HTTP_BALANCE.",
          "anyOf": [
            {
              "$ref": "#/$defs/Balance"
            },
            {
              "type": "null"
            }
          ]
        },
        "health_interval_secs": {
          "description": "Seconds between probes. Zero disables probes. Omitted or null inherits JAPKA_HEALTH_INTERVAL_SECS.",
          "type": [
            "integer",
            "null"
          ],
          "format": "uint32",
          "maximum": 4294967295,
          "minimum": 0
        },
        "health_path": {
          "description": "HTTP probe path starting with /. Omission inherits JAPKA_HEALTH_PATH. Explicit null selects TCP.",
          "type": [
            "string",
            "null"
          ],
          "pattern": "^/"
        }
      },
      "additionalProperties": false
    },
    "Route": {
      "type": "object",
      "properties": {
        "failover": {
          "description": "Retry eligible reads on another peer after a connection failure.",
          "type": "boolean",
          "default": false
        },
        "host": {
          "description": "Case-insensitive exact hostname or leading wildcard such as *.example.test. Omit to match any host.",
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "prefix": {
          "description": "Path prefix including its leading and trailing slash.",
          "type": "string",
          "pattern": "^/(?:[^?#]*/)?$"
        },
        "upstreams": {
          "description": "Ordered HTTP or HTTPS backend authorities.",
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1
        }
      },
      "additionalProperties": false,
      "required": [
        "prefix",
        "upstreams"
      ]
    },
    "Site": {
      "type": "object",
      "properties": {
        "host": {
          "description": "Exact hostname for this static site.",
          "type": "string"
        },
        "root": {
          "description": "Directory, relative to the configuration file or absolute.",
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "host",
        "root"
      ]
    },
    "TlsConfig": {
      "type": "object",
      "properties": {
        "cert": {
          "description": "PEM certificate chain path, relative to this configuration file or absolute.",
          "type": "string"
        },
        "hosts": {
          "description": "Additional certificate pairs selected by SNI hostname.",
          "type": "array",
          "items": {
            "$ref": "#/$defs/HostCertificate"
          }
        },
        "key": {
          "description": "Matching PEM private key path.",
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "cert",
        "key"
      ]
    }
  }
}
