{
  "openapi": "3.0.0",
  "info": {
    "title": "MeghiQ API",
    "version": "2.0.0",
    "description": "Enterprise Automation Governance Platform API - Comprehensive endpoints for automation discovery, monitoring, compliance, and AI insights",
    "contact": {
      "name": "MeghiQ Support",
      "email": "support@meghiq.com",
      "url": "https://www.meghiq.com"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://www.meghiq.com/terms"
    }
  },
  "servers": [
    {
      "url": "https://api.meghiq.com/v2",
      "description": "Production server"
    },
    {
      "url": "https://staging-api.meghiq.com/v2",
      "description": "Staging server"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    },
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Health Check",
        "description": "Check API health status and service availability",
        "security": [],
        "tags": ["System"],
        "responses": {
          "200": {
            "description": "API is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthStatus"
                }
              }
            }
          }
        }
      }
    },
    "/automations": {
      "get": {
        "summary": "List Automations",
        "description": "Get all discovered automation workflows with filtering and pagination",
        "tags": ["Automations"],
        "parameters": [
          {
            "name": "platform",
            "in": "query",
            "description": "Filter by automation platform",
            "schema": {
              "type": "string",
              "enum": ["zapier", "github", "jenkins", "aws", "azure", "power-automate"]
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filter by automation status",
            "schema": {
              "type": "string",
              "enum": ["active", "inactive", "error", "warning"]
            }
          },
          {
            "name": "page",
            "in": "query",
            "description": "Page number for pagination",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Number of items per page",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of automations with pagination info",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AutomationListResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "summary": "Create Automation Record",
        "description": "Manually register an automation for monitoring",
        "tags": ["Automations"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAutomationRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Automation created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Automation"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/automations/{id}": {
      "get": {
        "summary": "Get Automation Details",
        "description": "Get detailed information about a specific automation",
        "tags": ["Automations"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Automation ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Automation details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AutomationDetail"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/automations/{id}/dna": {
      "get": {
        "summary": "Get Automation DNA Profile",
        "description": "Get the unique DNA fingerprint and behavioral analysis for an automation",
        "tags": ["AI Features"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Automation ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "DNA profile data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DNAProfile"
                }
              }
            }
          }
        }
      }
    },
    "/predictions": {
      "get": {
        "summary": "Get AI Predictions",
        "description": "Get AI-powered failure predictions and optimization recommendations",
        "tags": ["AI Features"],
        "parameters": [
          {
            "name": "severity",
            "in": "query",
            "description": "Filter by prediction severity",
            "schema": {
              "type": "string",
              "enum": ["low", "medium", "high", "critical"]
            }
          },
          {
            "name": "timeframe",
            "in": "query",
            "description": "Prediction timeframe",
            "schema": {
              "type": "string",
              "enum": ["1h", "4h", "24h", "7d"],
              "default": "24h"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of predictions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Prediction"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/compliance/violations": {
      "get": {
        "summary": "Get Compliance Violations",
        "description": "Get current compliance violations across all automations",
        "tags": ["Compliance"],
        "parameters": [
          {
            "name": "framework",
            "in": "query",
            "description": "Compliance framework filter",
            "schema": {
              "type": "string",
              "enum": ["gdpr", "hipaa", "sox", "iso27001", "custom"]
            }
          },
          {
            "name": "severity",
            "in": "query",
            "description": "Violation severity",
            "schema": {
              "type": "string",
              "enum": ["low", "medium", "high", "critical"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of compliance violations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ComplianceViolation"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/analytics/costs": {
      "get": {
        "summary": "Get Cost Analytics",
        "description": "Get cost analysis and optimization opportunities",
        "tags": ["Analytics"],
        "parameters": [
          {
            "name": "period",
            "in": "query",
            "description": "Analysis period",
            "schema": {
              "type": "string",
              "enum": ["7d", "30d", "90d", "1y"],
              "default": "30d"
            }
          },
          {
            "name": "platform",
            "in": "query",
            "description": "Platform filter",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Cost analytics data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CostAnalytics"
                }
              }
            }
          }
        }
      }
    },
    "/integrations": {
      "get": {
        "summary": "List Platform Integrations",
        "description": "Get all connected automation platforms",
        "tags": ["Integrations"],
        "responses": {
          "200": {
            "description": "List of platform integrations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Integration"
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create Platform Integration",
        "description": "Connect a new automation platform",
        "tags": ["Integrations"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateIntegrationRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Integration created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Integration"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      },
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Unauthorized - Invalid or missing authentication",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "BadRequest": {
        "description": "Bad Request - Invalid parameters",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limit exceeded",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        },
        "headers": {
          "X-RateLimit-Limit": {
            "description": "Request limit per minute",
            "schema": {
              "type": "integer"
            }
          },
          "X-RateLimit-Remaining": {
            "description": "Remaining requests in current window",
            "schema": {
              "type": "integer"
            }
          },
          "X-RateLimit-Reset": {
            "description": "Time when rate limit resets",
            "schema": {
              "type": "integer"
            }
          }
        }
      }
    },
    "schemas": {
      "HealthStatus": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "healthy",
            "enum": ["healthy", "degraded", "unhealthy"]
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "version": {
            "type": "string",
            "example": "2.0.0"
          },
          "services": {
            "type": "object",
            "properties": {
              "database": {
                "type": "string",
                "enum": ["healthy", "degraded", "unhealthy"]
              },
              "ai_engine": {
                "type": "string",
                "enum": ["healthy", "degraded", "unhealthy"]
              },
              "integrations": {
                "type": "string",
                "enum": ["healthy", "degraded", "unhealthy"]
              }
            }
          }
        }
      },
      "Automation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique automation identifier"
          },
          "name": {
            "type": "string",
            "description": "Human-readable automation name"
          },
          "platform": {
            "type": "string",
            "enum": ["zapier", "github", "jenkins", "aws", "azure", "power-automate"],
            "description": "Source platform"
          },
          "status": {
            "type": "string",
            "enum": ["active", "inactive", "error", "warning"],
            "description": "Current automation status"
          },
          "type": {
            "type": "string",
            "description": "Automation type or category"
          },
          "lastRun": {
            "type": "string",
            "format": "date-time",
            "description": "Last execution timestamp"
          },
          "healthScore": {
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "description": "AI-calculated health score (0-100)"
          },
          "costPerMonth": {
            "type": "number",
            "description": "Estimated monthly cost in USD"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "User-defined tags"
          }
        },
        "required": ["id", "name", "platform", "status"]
      },
      "AutomationDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Automation"
          },
          {
            "type": "object",
            "properties": {
              "description": {
                "type": "string",
                "description": "Automation description"
              },
              "dependencies": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "IDs of dependent automations"
              },
              "executionHistory": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ExecutionRecord"
                }
              },
              "complianceStatus": {
                "$ref": "#/components/schemas/ComplianceStatus"
              }
            }
          }
        ]
      },
      "AutomationListResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Automation"
            }
          },
          "pagination": {
            "$ref": "#/components/schemas/PaginationInfo"
          },
          "total": {
            "type": "integer",
            "description": "Total number of automations"
          }
        }
      },
      "DNAProfile": {
        "type": "object",
        "properties": {
          "fingerprint": {
            "type": "string",
            "description": "Unique DNA fingerprint hash"
          },
          "personality": {
            "type": "string",
            "enum": ["reliable", "aggressive", "cautious", "experimental"],
            "description": "Automation personality type"
          },
          "behaviorPatterns": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "pattern": {
                  "type": "string"
                },
                "confidence": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                }
              }
            }
          },
          "similarAutomations": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "automationId": {
                  "type": "string"
                },
                "similarity": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                }
              }
            }
          }
        }
      },
      "Prediction": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "automationId": {
            "type": "string",
            "description": "Target automation ID"
          },
          "type": {
            "type": "string",
            "enum": ["failure", "performance_degradation", "cost_spike", "compliance_violation"],
            "description": "Prediction type"
          },
          "severity": {
            "type": "string",
            "enum": ["low", "medium", "high", "critical"]
          },
          "probability": {
            "type": "number",
            "format": "float",
            "minimum": 0,
            "maximum": 1,
            "description": "Prediction probability (0.0-1.0)"
          },
          "timeToEvent": {
            "type": "integer",
            "description": "Estimated time to event in minutes"
          },
          "recommendation": {
            "type": "string",
            "description": "AI-generated recommendation"
          },
          "confidence": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "description": "Model confidence level"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": ["id", "automationId", "type", "severity", "probability"]
      },
      "ComplianceViolation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "automationId": {
            "type": "string"
          },
          "framework": {
            "type": "string",
            "enum": ["gdpr", "hipaa", "sox", "iso27001", "custom"]
          },
          "ruleId": {
            "type": "string"
          },
          "severity": {
            "type": "string",
            "enum": ["low", "medium", "high", "critical"]
          },
          "description": {
            "type": "string"
          },
          "remediation": {
            "type": "string"
          },
          "detectedAt": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "type": "string",
            "enum": ["open", "acknowledged", "resolved", "false_positive"]
          }
        }
      },
      "CostAnalytics": {
        "type": "object",
        "properties": {
          "totalCost": {
            "type": "number",
            "description": "Total cost for the period"
          },
          "projectedSavings": {
            "type": "number",
            "description": "Potential savings from optimizations"
          },
          "costByPlatform": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "platform": {
                  "type": "string"
                },
                "cost": {
                  "type": "number"
                },
                "percentage": {
                  "type": "number"
                }
              }
            }
          },
          "optimizationOpportunities": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "enum": ["consolidation", "scheduling", "deduplication", "right_sizing"]
                },
                "description": {
                  "type": "string"
                },
                "estimatedSavings": {
                  "type": "number"
                },
                "effort": {
                  "type": "string",
                  "enum": ["low", "medium", "high"]
                }
              }
            }
          }
        }
      },
      "Integration": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "platform": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": ["connected", "disconnected", "error", "syncing"]
          },
          "lastSync": {
            "type": "string",
            "format": "date-time"
          },
          "automationsFound": {
            "type": "integer"
          },
          "configuration": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "CreateAutomationRequest": {
        "type": "object",
        "required": ["name", "platform"],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "platform": {
            "type": "string"
          },
          "description": {
            "type": "string",
            "maxLength": 1000
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "CreateIntegrationRequest": {
        "type": "object",
        "required": ["platform", "credentials"],
        "properties": {
          "platform": {
            "type": "string"
          },
          "credentials": {
            "type": "object",
            "description": "Platform-specific authentication credentials"
          },
          "configuration": {
            "type": "object",
            "description": "Platform-specific configuration options"
          }
        }
      },
      "ExecutionRecord": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "startTime": {
            "type": "string",
            "format": "date-time"
          },
          "endTime": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "type": "string",
            "enum": ["success", "failure", "timeout", "cancelled"]
          },
          "duration": {
            "type": "integer",
            "description": "Execution duration in milliseconds"
          },
          "error": {
            "type": "string",
            "description": "Error message if execution failed"
          }
        }
      },
      "ComplianceStatus": {
        "type": "object",
        "properties": {
          "overallScore": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "frameworkScores": {
            "type": "object",
            "additionalProperties": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            }
          },
          "violations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ComplianceViolation"
            }
          }
        }
      },
      "PaginationInfo": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer",
            "minimum": 1
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100
          },
          "totalPages": {
            "type": "integer",
            "minimum": 0
          },
          "hasNext": {
            "type": "boolean"
          },
          "hasPrevious": {
            "type": "boolean"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "description": "Error code"
              },
              "message": {
                "type": "string",
                "description": "Human-readable error message"
              },
              "details": {
                "type": "object",
                "description": "Additional error details"
              },
              "timestamp": {
                "type": "string",
                "format": "date-time"
              }
            },
            "required": ["code", "message"]
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "System",
      "description": "System health and status endpoints"
    },
    {
      "name": "Automations",
      "description": "Automation discovery and management"
    },
    {
      "name": "AI Features",
      "description": "AI-powered insights and predictions"
    },
    {
      "name": "Compliance",
      "description": "Compliance monitoring and violations"
    },
    {
      "name": "Analytics",
      "description": "Cost analytics and optimization"
    },
    {
      "name": "Integrations",
      "description": "Platform integrations and connectivity"
    }
  ]
}