{
  "openapi": "3.0.3",
  "info": {
    "title": "D3 Domain Due Diligence API",
    "version": "1.0.0",
    "description": "REST API for D3 domain intelligence platform. Authenticate with Bearer d3_live_<key>.",
    "contact": {
      "name": "D3 Support",
      "url": "https://domain-due-diligence.com/contact"
    },
    "license": {
      "name": "Commercial",
      "url": "https://domain-due-diligence.com/documents/terms"
    }
  },
  "servers": [
    {
      "url": "https://api.domain-due-diligence.com/api/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "d3_live_<hex>"
      }
    },
    "schemas": {
      "ScanProduct": {
        "type": "object",
        "properties": {
          "slug": {
            "type": "string",
            "example": "explorer"
          },
          "name": {
            "type": "string",
            "example": "D3 Explorer"
          },
          "description": {
            "type": "string"
          },
          "tagline": {
            "type": "string"
          },
          "creditCost": {
            "type": "integer",
            "example": 5
          }
        }
      },
      "ScanResult": {
        "type": "object",
        "properties": {
          "connector": {
            "type": "string",
            "example": "dns-basic"
          },
          "category": {
            "type": "string",
            "example": "DNS"
          },
          "tld": {
            "type": "string",
            "nullable": true
          },
          "score": {
            "type": "integer",
            "nullable": true
          },
          "riskLevel": {
            "type": "string",
            "enum": [
              "Low",
              "Medium",
              "High",
              "Critical"
            ],
            "nullable": true
          },
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "error"
            ]
          },
          "durationMs": {
            "type": "integer",
            "nullable": true
          },
          "data": {
            "type": "object"
          }
        }
      },
      "Scan": {
        "type": "object",
        "properties": {
          "scanId": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "QUEUED",
              "RUNNING",
              "COMPLETED",
              "FAILED"
            ]
          },
          "domain": {
            "type": "string"
          },
          "tlds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "product": {
            "type": "string"
          },
          "creditsDebited": {
            "type": "integer"
          },
          "overallScore": {
            "type": "integer",
            "nullable": true
          },
          "reportHash": {
            "type": "string",
            "nullable": true
          },
          "aiSummary": {
            "type": "string",
            "nullable": true
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ScanResult"
            }
          }
        }
      },
      "ApiKey": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "keyPrefix": {
            "type": "string",
            "example": "d3_live_xxxx"
          },
          "isSandbox": {
            "type": "boolean"
          },
          "restProductionAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "mcpProductionAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "enabled": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "integer"
          },
          "message": {
            "type": "string"
          },
          "error": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/products": {
      "get": {
        "summary": "List scan products",
        "operationId": "listProducts",
        "tags": [
          "Products"
        ],
        "responses": {
          "200": {
            "description": "List of enabled scan products",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "products": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ScanProduct"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/scans": {
      "post": {
        "summary": "Start a new scan",
        "operationId": "createScan",
        "tags": [
          "Scans"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "domain",
                  "product"
                ],
                "properties": {
                  "domain": {
                    "type": "string",
                    "example": "example.com"
                  },
                  "product": {
                    "type": "string",
                    "enum": [
                      "explorer",
                      "security_audit",
                      "valuation",
                      "due_diligence"
                    ]
                  },
                  "tlds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "example": [
                      "com",
                      "nl",
                      "be"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Scan queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Scan"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid API key"
          },
          "402": {
            "description": "Insufficient credits"
          },
          "409": {
            "description": "Scan already in progress"
          }
        }
      }
    },
    "/scans/{id}": {
      "get": {
        "summary": "Get scan status and results",
        "operationId": "getScan",
        "tags": [
          "Scans"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Scan object",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Scan"
                }
              }
            }
          },
          "404": {
            "description": "Scan not found"
          }
        }
      }
    },
    "/scans/{id}/report": {
      "get": {
        "summary": "Get full D3 Certified Report",
        "operationId": "getScanReport",
        "tags": [
          "Scans"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Full report",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Scan"
                }
              }
            }
          },
          "404": {
            "description": "Scan not found"
          }
        }
      }
    },
    "/keys": {
      "get": {
        "summary": "List own API keys",
        "operationId": "listKeys",
        "tags": [
          "API Keys"
        ],
        "responses": {
          "200": {
            "description": "List of API keys",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "keys": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ApiKey"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a new API key",
        "operationId": "createKey",
        "tags": [
          "API Keys"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "creditLimit": {
                    "type": "integer",
                    "nullable": true
                  },
                  "expiresAt": {
                    "type": "string",
                    "format": "date-time",
                    "nullable": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created key with plaintext (shown once)",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiKey"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "plaintext": {
                          "type": "string"
                        },
                        "warning": {
                          "type": "string"
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/keys/{id}/activate": {
      "post": {
        "summary": "Activate production for a section",
        "operationId": "activateProduction",
        "tags": [
          "API Keys"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "section"
                ],
                "properties": {
                  "section": {
                    "type": "string",
                    "enum": [
                      "rest",
                      "mcp"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated API key"
          }
        }
      }
    },
    "/keys/{id}": {
      "delete": {
        "summary": "Revoke an API key",
        "operationId": "revokeKey",
        "tags": [
          "API Keys"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Revoked"
          }
        }
      }
    }
  }
}