{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/inboxguard-io/json-schema/inboxguard-io-domain-detail-schema.json",
  "title": "DomainDetail",
  "description": "Full detail for one monitored domain.",
  "x-generated": "2026-11-12",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/inboxguard-io-openapi.json#/components/schemas/DomainDetail",
  "type": "object",
  "properties": {
    "domain": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "domain": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "quota_used": {
          "type": "integer"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        }
      },
      "required": [
        "id",
        "domain",
        "status"
      ]
    },
    "latestScan": {
      "type": [
        "object",
        "null"
      ],
      "description": "Latest scan with all per-check JSON blobs. NOTE: stored check keys here are snake_case (`mta_sts`, `tls_rpt`, `mx_tls`), unlike the live /scan-domain response (`mtaSts`, `tlsRpt`, `mxTls`).",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "run_at": {
          "type": "string",
          "format": "date-time"
        },
        "score": {
          "type": "integer"
        },
        "spf": {
          "$ref": "#/$defs/DomainCheck"
        },
        "dmarc": {
          "$ref": "#/$defs/DomainCheck"
        },
        "ptr": {
          "$ref": "#/$defs/DomainCheck"
        },
        "dkim": {
          "$ref": "#/$defs/DomainCheck"
        },
        "mta_sts": {
          "$ref": "#/$defs/DomainCheck"
        },
        "tls_rpt": {
          "$ref": "#/$defs/DomainCheck"
        },
        "mx_tls": {
          "$ref": "#/$defs/DomainCheck"
        },
        "blocklist": {
          "$ref": "#/$defs/DomainCheck"
        }
      }
    },
    "history": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "run_at": {
            "type": "string",
            "format": "date-time"
          },
          "score": {
            "type": "integer"
          }
        }
      },
      "description": "Last 30 scans (thin rows) for charting."
    },
    "alerts": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string"
          },
          "severity": {
            "type": "string",
            "enum": [
              "critical",
              "warn",
              "info"
            ]
          },
          "message": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "resolved_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "description": "Recent alerts for this domain (last 50)."
    },
    "postmaster": {
      "type": "object",
      "description": "Google Postmaster Tools state for this domain.",
      "properties": {
        "state": {
          "type": "string",
          "enum": [
            "not_connected",
            "connected_no_data",
            "active"
          ]
        },
        "verified": {
          "type": "boolean"
        },
        "latest": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "date": {
              "type": "string"
            },
            "spamRate": {
              "type": [
                "number",
                "null"
              ]
            },
            "domainReputation": {
              "type": [
                "string",
                "null"
              ]
            },
            "ipReputation": {
              "type": [
                "string",
                "null"
              ]
            },
            "dkimPassRate": {
              "type": [
                "number",
                "null"
              ]
            },
            "spfPassRate": {
              "type": [
                "number",
                "null"
              ]
            },
            "deliveryErrors": {}
          }
        }
      }
    }
  },
  "required": [
    "domain",
    "latestScan",
    "history",
    "alerts",
    "postmaster"
  ],
  "$defs": {
    "DomainCheck": {
      "type": "object",
      "description": "Result of one authentication/transport/reputation check. Carries `healthy` (boolean) and `issues` (array of {severity, message}) plus check-specific fields — e.g. SPF `record`/`lookupCount`/`allQualifier`/`permerrors`, DMARC `policy`/`pct`/`rua`, DKIM `keys[]` (selector, keyLengthBits, …), PTR `mxIps[]`, MTA-STS `policy`, BIMI `logoUrl`/`vmcUrl`, blocklist `hits[]`/`targets[]`/`checked`/`errored`. Exceptions: `mxTls` has `status` ('unsupported'|'pass'|'fail'|'partial') instead of `healthy` plus `basis` ('live'|'policy'|'none') describing how the verdict was reached — when an outbound STARTTLS probe isn't available the verdict is derived from MTA-STS/DANE policy (basis 'policy'); and `bimi` uses `found`/`logoReachable`/`displayEligible`.",
      "properties": {
        "healthy": {
          "type": "boolean",
          "description": "Whether this check passed cleanly (absent on mxTls and bimi — see description)."
        },
        "status": {
          "type": "string",
          "enum": [
            "unsupported",
            "pass",
            "fail",
            "partial"
          ],
          "description": "mxTls only — the transport-TLS verdict (used instead of `healthy`)."
        },
        "basis": {
          "type": "string",
          "enum": [
            "live",
            "policy",
            "none"
          ],
          "description": "mxTls only — how `status` was determined: 'live' (real STARTTLS handshake), 'policy' (derived from MTA-STS enforce/testing or DANE when a live probe isn't available — needs no outbound port 25), or 'none' (no probe and no enforcing policy)."
        },
        "issues": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Issue"
          },
          "description": "Findings, each with severity and message."
        }
      },
      "additionalProperties": true
    },
    "Issue": {
      "type": "object",
      "description": "One finding inside a check.",
      "properties": {
        "severity": {
          "type": "string",
          "enum": [
            "info",
            "warn",
            "critical"
          ]
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "severity",
        "message"
      ]
    }
  }
}