{
  "openapi": "3.1.0",
  "info": {
    "title": "AegisLab Core API",
    "version": "1.0.0",
    "description": "AegisLab licensing, project catalog and AegisCore runtime API."
  },
  "servers": [
    {
      "url": "https://api.core.aegislab.top/v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "DeveloperApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "aegis_live_..."
      },
      "AegisRuntimeToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "summary": "API health",
        "responses": {
          "200": {
            "description": "Healthy"
          }
        }
      }
    },
    "/projects": {
      "get": {
        "summary": "List active AegisLab projects",
        "security": [
          {
            "DeveloperApiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Project list"
          },
          "401": {
            "description": "Invalid API key"
          },
          "403": {
            "description": "Missing projects.read scope"
          }
        }
      }
    },
    "/licenses/verify": {
      "post": {
        "summary": "Verify a license for a project",
        "security": [
          {
            "DeveloperApiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Verification result"
          },
          "401": {
            "description": "Invalid API key"
          },
          "403": {
            "description": "Missing licenses.verify scope"
          }
        }
      }
    },
    "/activate": {
      "post": {
        "summary": "AegisCore activation / heartbeat",
        "responses": {
          "200": {
            "description": "Signed runtime token"
          },
          "403": {
            "description": "License rejected"
          },
          "409": {
            "description": "Server identity mismatch"
          }
        }
      }
    },
    "/manifest/{channel}": {
      "get": {
        "summary": "Signed update manifest",
        "parameters": [
          {
            "name": "channel",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "stable",
                "beta",
                "dev"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Signed manifest"
          }
        }
      }
    },
    "/releases/{id}/download": {
      "get": {
        "summary": "Download a licensed release",
        "security": [
          {
            "AegisRuntimeToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "JAR bytes"
          },
          "401": {
            "description": "Missing or invalid runtime token"
          },
          "403": {
            "description": "Product is not licensed"
          }
        }
      }
    },
    "/store/provision": {
      "post": {
        "summary": "Create a store project and AegisCore mode licenses",
        "description": "Server-to-server endpoint for AegisLab Store. Idempotent by orderId.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "orderId",
                  "externalCustomerId",
                  "projectName",
                  "modeCount"
                ],
                "properties": {
                  "orderId": {
                    "type": "string"
                  },
                  "externalCustomerId": {
                    "type": "string"
                  },
                  "projectName": {
                    "type": "string"
                  },
                  "modeCount": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 20
                  },
                  "productSlugs": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "allProducts": {
                    "type": "boolean"
                  },
                  "channel": {
                    "type": "string",
                    "enum": [
                      "stable",
                      "beta",
                      "dev"
                    ]
                  },
                  "productCategory": {
                    "type": "string",
                    "enum": [
                      "all",
                      "relic",
                      "anarchy",
                      "vanilla"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Project and licenses created"
          },
          "200": {
            "description": "Existing provisioning returned idempotently"
          },
          "400": {
            "description": "Invalid provisioning payload"
          },
          "401": {
            "description": "Invalid API key"
          },
          "403": {
            "description": "Missing store.provision scope"
          },
          "409": {
            "description": "Order already provisioned with a different payload"
          }
        }
      }
    }
  }
}
