{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://nttcom.github.io/pola/schemas/server/polad_config.json",
    "title": "polad configuration",
    "type": "object",
    "$defs": {
        "address": {
            "description": "Literal IPv4 or IPv6 address. Host names are not resolved.",
            "type": "string",
            "anyOf": [
                {
                    "format": "ipv4"
                },
                {
                    "format": "ipv6"
                }
            ]
        },
        "port": {
            "description": "TCP port. polad reads it as a string, so a digits-only string is accepted as well as an integer.",
            "anyOf": [
                {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 65535
                },
                {
                    "type": "string",
                    "pattern": "^0*(?:[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$"
                }
            ]
        },
        "timer": {
            "type": "integer",
            "minimum": 0,
            "maximum": 255
        },
        "endpoint": {
            "type": "object",
            "properties": {
                "address": {
                    "$ref": "#/$defs/address"
                },
                "port": {
                    "$ref": "#/$defs/port"
                }
            },
            "required": [
                "address",
                "port"
            ],
            "additionalProperties": false
        }
    },
    "properties": {
        "global": {
            "type": "object",
            "properties": {
                "pcep": {
                    "type": "object",
                    "properties": {
                        "address": {
                            "$ref": "#/$defs/address"
                        },
                        "port": {
                            "$ref": "#/$defs/port"
                        },
                        "keepalive": {
                            "description": "Keepalive timer in seconds advertised in Open. Defaults to 30.",
                            "$ref": "#/$defs/timer"
                        },
                        "deadTimer": {
                            "description": "DeadTimer in seconds advertised in Open. Must be 0 when keepalive is 0; otherwise 0 or greater than keepalive (not expressible in JSON Schema, checked by polad).",
                            "$ref": "#/$defs/timer"
                        },
                        "minKeepalive": {
                            "description": "Must be <= maxKeepalive when both are set (checked by polad).",
                            "$ref": "#/$defs/timer"
                        },
                        "maxKeepalive": {
                            "$ref": "#/$defs/timer"
                        },
                        "allowNegotiation": {
                            "type": "boolean"
                        }
                    },
                    "required": [
                        "address",
                        "port"
                    ],
                    "additionalProperties": false,
                    "if": {
                        "properties": {
                            "keepalive": {
                                "const": 0
                            }
                        },
                        "required": [
                            "keepalive"
                        ]
                    },
                    "then": {
                        "properties": {
                            "deadTimer": {
                                "const": 0
                            }
                        }
                    }
                },
                "grpcServer": {
                    "$ref": "#/$defs/endpoint"
                },
                "log": {
                    "type": "object",
                    "properties": {
                        "path": {
                            "type": "string",
                            "minLength": 1
                        },
                        "name": {
                            "type": "string",
                            "minLength": 1
                        },
                        "level": {
                            "description": "An empty string means info.",
                            "enum": [
                                "",
                                "debug",
                                "info",
                                "warn",
                                "error"
                            ]
                        }
                    },
                    "required": [
                        "path",
                        "name"
                    ],
                    "additionalProperties": false
                },
                "ted": {
                    "type": "object",
                    "properties": {
                        "enable": {
                            "type": "boolean",
                            "default": false
                        },
                        "source": {
                            "enum": [
                                "gobgp"
                            ]
                        },
                        "asn": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 4294967295
                        }
                    },
                    "additionalProperties": false,
                    "if": {
                        "properties": {
                            "enable": {
                                "const": true
                            }
                        },
                        "required": [
                            "enable"
                        ]
                    },
                    "then": {
                        "required": [
                            "source",
                            "asn"
                        ]
                    }
                },
                "gobgp": {
                    "type": "object",
                    "properties": {
                        "grpcClient": {
                            "$ref": "#/$defs/endpoint"
                        }
                    },
                    "required": [
                        "grpcClient"
                    ],
                    "additionalProperties": false
                },
                "usidMode": {
                    "type": "boolean",
                    "default": false
                }
            },
            "required": [
                "pcep",
                "grpcServer",
                "log",
                "ted"
            ],
            "additionalProperties": false,
            "if": {
                "properties": {
                    "ted": {
                        "properties": {
                            "enable": {
                                "const": true
                            }
                        },
                        "required": [
                            "enable"
                        ]
                    }
                }
            },
            "then": {
                "required": [
                    "gobgp"
                ]
            }
        }
    },
    "required": [
        "global"
    ],
    "additionalProperties": false
}
