{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://nameocean.net/schemas/dns-zone.json",
  "title": "NameOcean DNS zone",
  "description": "A DNS zone on NameOcean as code. The file is the whole zone: `nameocean dns plan` shows the difference, `nameocean dns apply` makes the zone match. https://nameocean.net/developers/dns/",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "records"
  ],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "zone": {
      "type": "string",
      "description": "The zone (domain) this file is for, e.g. example.com."
    },
    "ttl": {
      "type": "string",
      "enum": [
        "5m",
        "15m",
        "30m",
        "1h",
        "1d"
      ],
      "description": "Default ttl for records that have none (default 1h)."
    },
    "records": {
      "type": "array",
      "maxItems": 2000,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "type",
          "value"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "\"@\" for the zone itself, a name relative to the zone (\"www\", \"_dmarc\"), or a fully qualified name ending in a dot. PTR: an IP address."
          },
          "type": {
            "type": "string",
            "enum": [
              "A",
              "AAAA",
              "CNAME",
              "MX",
              "TXT",
              "SRV",
              "PTR",
              "REDIRECT"
            ]
          },
          "value": {
            "type": "string",
            "description": "A/AAAA: IP address. TXT: the text. CNAME, MX, SRV, PTR: target host (\"@\" for the zone itself). REDIRECT: the URL to redirect to."
          },
          "ttl": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "5m",
                  "15m",
                  "30m",
                  "1h",
                  "1d"
                ],
                "description": "Cache time. Default: the file's ttl, else 1h."
              },
              {
                "const": "30",
                "description": "TXT only: 30 seconds"
              }
            ]
          },
          "priority": {
            "type": "integer",
            "minimum": 0,
            "maximum": 65535,
            "description": "MX (default 10) and SRV."
          },
          "weight": {
            "type": "integer",
            "minimum": 0,
            "maximum": 65535,
            "description": "SRV."
          },
          "port": {
            "type": "integer",
            "minimum": 0,
            "maximum": 65535,
            "description": "SRV."
          },
          "save_path": {
            "type": "boolean",
            "description": "REDIRECT: keep the request path (default true)."
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "type": {
                  "const": "SRV"
                }
              }
            },
            "then": {
              "required": [
                "priority",
                "weight",
                "port"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "type": {
                  "const": "REDIRECT"
                }
              }
            },
            "then": {
              "not": {
                "required": [
                  "ttl"
                ]
              }
            }
          }
        ]
      }
    }
  }
}