{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Verified Customer Proof report",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "report_id",
    "company_website",
    "checked_at",
    "completed_at",
    "status",
    "message",
    "customer_count",
    "customers",
    "sources",
    "coverage_complete",
    "source_errors",
    "http_request_count",
    "downloaded_bytes",
    "duration_ms",
    "billing_event",
    "billing_quantity"
  ],
  "properties": {
    "schema_version": {
      "const": "1.0"
    },
    "report_id": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "company_website": {
      "type": [
        "string",
        "null"
      ],
      "format": "uri"
    },
    "checked_at": {
      "type": "string",
      "format": "date-time"
    },
    "completed_at": {
      "type": "string",
      "format": "date-time"
    },
    "status": {
      "enum": [
        "verified_customer_proof",
        "unknown",
        "invalid_input"
      ]
    },
    "message": {
      "type": "string"
    },
    "customer_count": {
      "type": "integer",
      "minimum": 0,
      "maximum": 6
    },
    "customers": {
      "type": "array",
      "maxItems": 6,
      "items": {
        "$ref": "#/definitions/customer"
      }
    },
    "sources": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/source"
      }
    },
    "coverage_complete": {
      "const": false
    },
    "source_errors": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/source_error"
      }
    },
    "http_request_count": {
      "type": "integer",
      "minimum": 0,
      "maximum": 12
    },
    "downloaded_bytes": {
      "type": "integer",
      "minimum": 0
    },
    "duration_ms": {
      "type": "integer",
      "minimum": 0
    },
    "billing_event": {
      "type": [
        "string",
        "null"
      ]
    },
    "billing_quantity": {
      "type": "integer",
      "minimum": 0,
      "maximum": 1
    }
  },
  "definitions": {
    "customer": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "customer_name",
        "story_title",
        "source_url",
        "name_evidence_field",
        "checked_at",
        "evidence_sha256"
      ],
      "properties": {
        "customer_name": {
          "type": "string",
          "minLength": 2
        },
        "story_title": {
          "type": "string"
        },
        "source_url": {
          "type": "string",
          "format": "uri"
        },
        "name_evidence_field": {
          "enum": [
            "h1",
            "og:title",
            "title"
          ]
        },
        "checked_at": {
          "type": "string",
          "format": "date-time"
        },
        "evidence_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "url",
        "discovered_from",
        "source_type",
        "checked_at",
        "evidence_sha256"
      ],
      "properties": {
        "url": {
          "type": "string",
          "format": "uri"
        },
        "discovered_from": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "source_type": {
          "enum": [
            "company_homepage",
            "customer_stories_index",
            "customer_story"
          ]
        },
        "checked_at": {
          "type": "string",
          "format": "date-time"
        },
        "evidence_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      }
    },
    "source_error": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "url",
        "error_code"
      ],
      "properties": {
        "url": {
          "type": [
            "string",
            "null"
          ]
        },
        "error_code": {
          "type": "string"
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "status": {
            "const": "verified_customer_proof"
          }
        }
      },
      "then": {
        "properties": {
          "customer_count": {
            "minimum": 1
          },
          "customers": {
            "minItems": 1
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "enum": [
              "unknown",
              "invalid_input"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "customer_count": {
            "const": 0
          },
          "customers": {
            "maxItems": 0
          }
        }
      }
    }
  ]
}
