{
  "openapi": "3.1.0",
  "info": {
    "title": "AgentReady API",
    "version": "0.2.0"
  },
  "servers": [
    {
      "url": "https://agentready.ir"
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "summary": "Service readiness",
        "responses": {
          "200": {
            "description": "API, D1 and scanner available"
          },
          "503": {
            "description": "Service unavailable"
          }
        }
      }
    },
    "/api/v1/domains": {
      "get": {
        "summary": "Public domain directory",
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "description": "How to order and filter the directory.",
            "schema": {
              "type": "string",
              "enum": [
                "newest",
                "best",
                "worst",
                "unavailable",
                "most_scanned",
                "biggest_change"
              ],
              "default": "newest"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 48,
              "default": 24
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated domain list with latest status, scan count and score delta"
          }
        }
      }
    },
    "/api/v1/audits": {
      "post": {
        "summary": "Create or reuse public audit",
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "https://agentready.ir"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["url"],
                "properties": {
                  "url": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing audit"
          },
          "202": {
            "description": "Audit accepted"
          },
          "429": {
            "description": "Quota or rate limit exceeded"
          }
        }
      }
    },
    "/api/v1/audits/{id}": {
      "get": {
        "summary": "Read public audit",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Completed or failed audit"
          },
          "202": {
            "description": "Audit pending"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    }
  }
}
