{
  "openapi": "3.1.0",
  "info": {
    "title": "Spark AI API",
    "description": "AI-powered custom software that replaces SaaS subscriptions. Browse templates, get quotes, and submit contact requests programmatically.",
    "version": "2.0.0",
    "contact": {
      "name": "Spark AI",
      "email": "hello@spark-ai.be",
      "url": "https://sparkcollective.be"
    }
  },
  "servers": [
    { "url": "https://uzdlmwhvlzmjzkjcjgut.supabase.co/functions/v1", "description": "Supabase Edge Functions" },
    { "url": "https://sparkcollective.be", "description": "Static discovery" }
  ],
  "paths": {
    "/api-templates": {
      "get": {
        "operationId": "listTemplates",
        "summary": "List all available software templates with pricing and features",
        "responses": {
          "200": {
            "description": "List of active templates",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "templates": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Template" }
                    },
                    "count": { "type": "integer" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api-quote": {
      "post": {
        "operationId": "requestQuote",
        "summary": "Get a pricing estimate for a project",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/QuoteRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pricing estimate with breakdown",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/QuoteResponse" }
              }
            }
          }
        }
      }
    },
    "/api-contact": {
      "post": {
        "operationId": "submitContact",
        "summary": "Submit a contact/lead form programmatically",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ContactRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Submission confirmation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "submission_id": { "type": "string" },
                    "message": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/webhook-calcom": {
      "post": {
        "operationId": "webhookCalcom",
        "summary": "Webhook receiver for cal.com booking events",
        "description": "Receives BOOKING_CREATED, BOOKING_CANCELLED, and BOOKING_RESCHEDULED events from cal.com and stores them in the bookings table.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["triggerEvent", "payload"],
                "properties": {
                  "triggerEvent": { "type": "string", "description": "Cal.com event type (e.g. BOOKING_CREATED)" },
                  "payload": { "type": "object", "description": "Cal.com booking payload" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Event processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "event": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/agentic.json": {
      "get": {
        "operationId": "getAgenticData",
        "summary": "Get full Spark AI structured data for agent consumption",
        "responses": {
          "200": { "description": "Full Spark AI structured data" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Template": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "description": { "type": "string" },
          "category": { "type": "string" },
          "price": { "type": "number" },
          "features": { "type": "array", "items": { "type": "string" } },
          "active": { "type": "boolean" }
        }
      },
      "QuoteRequest": {
        "type": "object",
        "properties": {
          "template_name": { "type": "string", "description": "Name of template (partial match)" },
          "features": { "type": "array", "items": { "type": "string" }, "description": "Additional features needed" },
          "timeline": { "type": "string", "enum": ["relaxed", "standard", "rush", "urgent"] },
          "complexity": { "type": "string", "enum": ["simple", "standard", "complex", "enterprise"] },
          "contact_email": { "type": "string" },
          "contact_name": { "type": "string" },
          "notes": { "type": "string" }
        }
      },
      "QuoteResponse": {
        "type": "object",
        "properties": {
          "quote_id": { "type": "string", "format": "uuid" },
          "estimated_price": { "type": "number" },
          "currency": { "type": "string" },
          "breakdown": {
            "type": "object",
            "properties": {
              "base_price": { "type": "number" },
              "complexity_multiplier": { "type": "number" },
              "timeline_multiplier": { "type": "number" },
              "feature_addon": { "type": "number" }
            }
          },
          "message": { "type": "string" },
          "book_consultation": { "type": "string", "format": "uri" }
        }
      },
      "ContactRequest": {
        "type": "object",
        "required": ["name", "email"],
        "properties": {
          "name": { "type": "string" },
          "email": { "type": "string", "format": "email" },
          "company": { "type": "string" },
          "message": { "type": "string" },
          "source": { "type": "string", "description": "Where the lead came from (e.g. 'chatgpt', 'claude')" }
        }
      }
    }
  }
}
