{
    "id": "record",

    "$schema": "http://json-schema.org/draft-03/hyper-schema",

    "title": "record",
    "description": "Record",
    "additionalProperties": false,

    "properties": {
        "id": {
            "type": "string",
            "description": "Record Identifier",
            "format": "uuid",
            "readonly": true
        },
        "domain_id": {
            "type": "string",
            "description": "Domain Identifier",
            "format": "uuid",
            "readonly": true
        },
        "name": {
            "type": "string",
            "description": "DNS Record Name",
            "format": "host-name",
            "maxLength": 255,
            "required": true
        },
        "type": {
            "type": "string",
            "description": "DNS Record Type",
            "enum": ["A", "AAAA", "CNAME", "MX", "SRV", "TXT", "SPF", "NS", "PTR", "SSHFP", "SOA"],
            "required": true
        },
        "data": {
            "type": "string",
            "description": "DNS Record Value",
            "maxLength": 255,
            "required": true
        },
        "priority": {
            "type": ["integer", "null"],
            "description": "DNS Record Priority",
            "minimum": 0,
            "maximum": 65535
        },
        "ttl": {
            "type": ["integer", "null"],
            "description": "Time to live",
            "minimum": 1,
            "maximum": 2147483647
        },
        "description": {
            "type": ["string", "null"],
            "description": "Description for the record",
            "maxLength": 160
        },
        "created_at": {
            "type": "string",
            "description": "Date and time of record creation",
            "format": "date-time",
            "readonly": true
        },
        "updated_at": {
            "type": ["string", "null"],
            "description": "Date and time of last record update",
            "format": "date-time",
            "readonly": true
        }
    },
    "oneOf": [{
        "description": "An A Record",
        "properties": {
            "type": {
                "type": "string",
                "enum": ["A"]
            },
            "data": {
                "format": "ip-address",
                "required": true
            },
            "priority": {
                "type": "null"
            }
        }
    }, {
        "description": "An AAAA Record",
        "properties": {
            "type": {
                "type": "string",
                "enum": ["AAAA"]
            },
            "data": {
                "format": "ipv6",
                "required": true
            },
            "priority": {
                "type": "null"
            }
        }
    }, {
        "description": "A CNAME Record",
        "properties": {
            "type": {
                "type": "string",
                "enum": ["CNAME"]
            },
            "data": {
                "format": "host-name",
                "required": true
            },
            "priority": {
                "type": "null"
            }
        }
    }, {
        "description": "A MX Record",
        "properties": {
            "type": {
                "type": "string",
                "enum": ["MX"]
            },
            "data": {
                "format": "host-name",
                "required": true
            },
            "priority": {
                "type": "integer",
                "required": true
            }
        }
    }, {
        "description": "A SRV Record",
        "properties": {
            "type": {
                "type": "string",
                "enum": ["SRV"]
            },
            "name": {
                "type": "string",
                "pattern": "^(?:_[A-Za-z0-9_\\-]{1,62}\\.){2}"
            },
            "data": {
                "type": "string",
                "pattern": "^(?:(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9])\\s){2}(?!.{255,})((?!\\-)[A-Za-z0-9_\\-]{1,63}(?<!\\-)\\.)+$"
            },
            "priority": {
                "type": "integer",
                "required": true
            }
        }
    }, {
        "description": "A TXT Record",
        "properties": {
            "type": {
                "type": "string",
                "enum": ["TXT"]
            },
            "priority": {
                "type": "null"
            }
        }
    }, {
        "description": "A SPF Record",
        "properties": {
            "type": {
                "type": "string",
                "enum": ["SPF"]
            },
            "priority": {
                "type": "null"
            }
        }
    }, {
        "description": "A NS Record",
        "properties": {
            "type": {
                "type": "string",
                "enum": ["NS"]
            },
            "data": {
                "format": "host-name",
                "required": true
            },
            "priority": {
                "type": "null"
            }
        }
    }, {
        "description": "A PTR Record",
        "properties": {
            "type": {
                "type": "string",
                "enum": ["PTR"]
            },
            "name": {
                "type": "string",
                "pattern": "^(?:(?:\\d{1,3}\\.){4}in-addr\\.arpa\\.|(?:[a-f|\\d]\\.){32}ip6\\.arpa\\.)$"
            },
            "data": {
                "format": "host-name",
                "required": true
            },
            "priority": {
                "type": "null"
            }
        }
    }, {
        "description": "A SSHFP Record",
        "properties": {
            "type": {
                "type": "string",
                "enum": ["SSHFP"]
            },
            "data": {
                "pattern": "^[1-2] 1 [0-9A-Fa-f]{40}$",
                "required": true
            },
            "priority": {
                "type": "null"
            }
        }
    }, {
        "description": "A SOA Record",
        "properties": {
            "type": {
                "type": "string",
                "enum": ["SOA"]
            },
            "priority": {
                "type": "null"
            }
        }
    }],
    "links": [{
        "rel": "self",
        "href": "/domains/{domain_id}/records/{id}"
    }, {
        "rel": "domain",
        "href": "/domains/{domain_id}"
    }, {
        "rel": "collection",
        "href": "/domains/{domain_id}/records"
    }]
}
