{
  "openapi": "3.1.0",
  "info": {
    "title": "QuietDiff",
    "version": "1.0.0",
    "description": "Agent-first web change monitoring API with AI-powered significance filtering",
    "contact": {
      "email": "support@quietdiff.com"
    }
  },
  "servers": [
    {
      "url": "https://api.quietdiff.com/v1",
      "description": "Production"
    },
    {
      "url": "http://localhost:43210/api/v1",
      "description": "Development"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "Monitor": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "url": { "type": "string", "format": "uri" },
          "status": { "type": "string", "enum": ["ACTIVE", "PAUSED", "DISABLED"] },
          "health": { "type": "string", "enum": ["HEALTHY", "DEGRADED", "FAILING"] },
          "fields": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": { "type": "string" },
                "selector": { "type": "string" },
                "description": { "type": "string" },
                "type": { "type": "string", "enum": ["text", "number", "price", "boolean", "date"] }
              }
            }
          },
          "checkInterval": { "type": "integer", "description": "Check interval in seconds" },
          "aiCondition": { "type": "string", "description": "Plain-English condition for AI filtering" },
          "lastCheckedAt": { "type": "string", "format": "date-time" },
          "lastChangeAt": { "type": "string", "format": "date-time" },
          "createdAt": { "type": "string", "format": "date-time" }
        }
      },
      "Change": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "field": { "type": "string" },
          "oldValue": { "type": "string", "nullable": true },
          "newValue": { "type": "string" },
          "changeType": { "type": "string" },
          "significance": { "type": "string", "enum": ["TRIVIAL", "MINOR", "SIGNIFICANT", "CRITICAL"] },
          "aiSummary": { "type": "string" },
          "confirmed": { "type": "boolean" },
          "createdAt": { "type": "string", "format": "date-time" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string" }
        }
      }
    }
  },
  "paths": {
    "/monitors": {
      "get": {
        "summary": "List monitors",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": { "type": "string", "enum": ["ACTIVE", "PAUSED", "DISABLED"] }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": { "type": "integer", "default": 50, "maximum": 100 }
          }
        ],
        "responses": {
          "200": {
            "description": "List of monitors",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "monitors": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Monitor" }
                    },
                    "count": { "type": "integer" }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create monitor",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name", "url", "fields"],
                "properties": {
                  "name": { "type": "string" },
                  "url": { "type": "string", "format": "uri" },
                  "fields": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": { "type": "string" },
                        "selector": { "type": "string" },
                        "description": { "type": "string" },
                        "type": { "type": "string" }
                      }
                    }
                  },
                  "checkInterval": { "type": "integer" },
                  "aiCondition": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Monitor created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "monitor": { "$ref": "#/components/schemas/Monitor" }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Quota exceeded"
          }
        }
      }
    },
    "/monitors/{id}": {
      "get": {
        "summary": "Get monitor",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Monitor details"
          },
          "404": {
            "description": "Monitor not found"
          }
        }
      },
      "patch": {
        "summary": "Update monitor",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": { "type": "string" },
                  "status": { "type": "string", "enum": ["ACTIVE", "PAUSED", "DISABLED"] },
                  "checkInterval": { "type": "integer" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Monitor updated"
          }
        }
      },
      "delete": {
        "summary": "Delete monitor",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Monitor deleted"
          }
        }
      }
    },
    "/monitors/{id}/changes": {
      "get": {
        "summary": "List changes for monitor",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          },
          {
            "name": "significance",
            "in": "query",
            "schema": { "type": "string", "enum": ["TRIVIAL", "MINOR", "SIGNIFICANT", "CRITICAL"] }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": { "type": "integer", "default": 20 }
          }
        ],
        "responses": {
          "200": {
            "description": "List of changes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "changes": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Change" }
                    },
                    "count": { "type": "integer" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
