{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://developers.crawlhub.ai/reference/proxy-v1.schema.json",
  "title": "Crawlhub proxy username contract v1",
  "description": "Syntax specification for planned gateway rollout. Validation is not network activation, authentication or inventory validation.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "account",
    "network"
  ],
  "properties": {
    "account": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_]{1,64}$",
      "description": "Assigned proxy account ID, not a login email or dashboard UUID."
    },
    "network": {
      "enum": [
        "residential",
        "isp",
        "datacenter"
      ]
    },
    "country": {
      "type": "string",
      "pattern": "^[a-z]{2}$",
      "description": "Lowercase country code. Activated inventory must be validated by the gateway."
    },
    "state": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$",
      "maxLength": 64
    },
    "city": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$",
      "maxLength": 64
    },
    "zip": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$",
      "maxLength": 64
    },
    "asn": {
      "type": "integer",
      "minimum": 1,
      "maximum": 4294967295
    },
    "session": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_]{1,64}$"
    },
    "ttl": {
      "type": "integer",
      "minimum": 60,
      "maximum": 3600,
      "default": 600
    },
    "ip": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_]{1,64}$",
      "description": "An assigned allocation ID, not an arbitrary IP address."
    }
  },
  "allOf": [
    {
      "if": {
        "required": [
          "state"
        ]
      },
      "then": {
        "required": [
          "country"
        ]
      }
    },
    {
      "if": {
        "required": [
          "city"
        ]
      },
      "then": {
        "required": [
          "country"
        ]
      }
    },
    {
      "if": {
        "required": [
          "zip"
        ]
      },
      "then": {
        "required": [
          "country"
        ]
      }
    },
    {
      "if": {
        "required": [
          "ttl"
        ]
      },
      "then": {
        "required": [
          "session"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "network": {
            "const": "residential"
          }
        }
      },
      "then": {
        "not": {
          "required": [
            "ip"
          ]
        }
      },
      "else": {
        "not": {
          "anyOf": [
            {
              "required": [
                "state"
              ]
            },
            {
              "required": [
                "city"
              ]
            },
            {
              "required": [
                "zip"
              ]
            },
            {
              "required": [
                "asn"
              ]
            },
            {
              "required": [
                "session"
              ]
            },
            {
              "required": [
                "ttl"
              ]
            }
          ]
        }
      }
    }
  ],
  "$comment": "The formatter also enforces the 255-byte serialized username limit. Schema validation alone does not prove account ownership or inventory availability.",
  "x-crawlhub-max-username-bytes": 255,
  "x-crawlhub-validator-sha256": "3a61e7e9e0a015e08f0f1e413b3b81a99685d1f911f03bb7db91da29dee7da8c"
}
