{
  "openapi": "3.1.0",
  "info": {
    "title": "domande.ch Public REST & AI API",
    "description": "API pubblica e specifica per l'integrazione di form, sondaggi, generazione AI e server MCP in domande.ch.",
    "version": "1.0.0",
    "contact": {
      "name": "domande.ch Support",
      "url": "https://domande.ch/docs/ai"
    }
  },
  "servers": [
    {
      "url": "https://domande.ch/api",
      "description": "Production API Server"
    }
  ],
  "paths": {
    "/v1/forms": {
      "post": {
        "summary": "Crea un nuovo modulo (Manualmente o con Prompt IA)",
        "operationId": "createForm",
        "security": [{ "ApiKeyAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": { "type": "string" },
                  "description": { "type": "string" },
                  "prompt": { "type": "string", "description": "Descrizione in linguaggio naturale per generare il form via IA" },
                  "status": { "type": "string", "enum": ["draft", "published"] },
                  "theme": { "type": "string", "enum": ["neutral", "indigo", "emerald", "amber", "rose", "sky"] },
                  "fields": {
                    "type": "array",
                    "items": { "$ref": "#/components/schemas/FormField" }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Form creato con successo" },
          "401": { "description": "Non autorizzato" }
        }
      }
    },
    "/v1/forms/{formId}": {
      "get": {
        "summary": "Ottieni dettagli di un modulo",
        "operationId": "getForm",
        "parameters": [
          { "name": "formId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Dettagli del modulo" },
          "404": { "description": "Modulo non trovato" }
        }
      },
      "patch": {
        "summary": "Aggiorna un modulo esistente",
        "operationId": "updateForm",
        "security": [{ "ApiKeyAuth": [] }],
        "parameters": [
          { "name": "formId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Form aggiornato" }
        }
      },
      "delete": {
        "summary": "Elimina un modulo",
        "operationId": "deleteForm",
        "security": [{ "ApiKeyAuth": [] }],
        "parameters": [
          { "name": "formId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Form eliminato" }
        }
      }
    },
    "/v1/forms/{formId}/submissions": {
      "get": {
        "summary": "Leggi tutte le risposte ricevute per un modulo (Solo proprietario)",
        "operationId": "getSubmissions",
        "security": [{ "ApiKeyAuth": [] }],
        "parameters": [
          { "name": "formId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Lista di risposte" }
        }
      },
      "post": {
        "summary": "Invia una risposta pubblica ad un modulo pubblicato",
        "operationId": "submitAnswers",
        "parameters": [
          { "name": "formId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "answers": { "type": "object", "additionalProperties": true }
                },
                "required": ["answers"]
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Risposta registrata con successo" }
        }
      }
    },
    "/mcp": {
      "post": {
        "summary": "Model Context Protocol (MCP) JSON-RPC 2.0 Endpoint",
        "operationId": "mcpHandler",
        "security": [{ "ApiKeyAuth": [] }],
        "responses": {
          "200": { "description": "Risposta JSON-RPC 2.0" }
        }
      }
    },
    "/ai-info": {
      "get": {
        "summary": "Metadati ed elenchi di capability per Agenti AI",
        "operationId": "getAiInfo",
        "responses": {
          "200": { "description": "Informazioni e risorse AI" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key (dom_sk_...)"
      }
    },
    "schemas": {
      "FormField": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "type": { "type": "string", "enum": ["text", "paragraph", "radio", "checkbox", "rating", "dropdown"] },
          "label": { "type": "string" },
          "required": { "type": "boolean" },
          "placeholder": { "type": "string" },
          "options": { "type": "array", "items": { "type": "string" } }
        },
        "required": ["id", "type", "label", "required"]
      }
    }
  }
}
