{
 "openapi": "3.1.0",
 "info": {
  "title": "API pública de EIYA Estrategia",
  "version": "1.0.0",
  "description": "Permite enviar una consulta al equipo de EIYA Estrategia y conversar con su agente de bienvenida. Enviar datos implica aceptar el aviso de privacidad en https://eiyaestrategia.com/aviso-de-privacidad/."
 },
 "servers": [
  {
   "url": "https://eiyaestrategia.com"
  }
 ],
 "paths": {
  "/api/contact": {
   "post": {
    "operationId": "enviarConsulta",
    "summary": "Envía una consulta al equipo. Una persona responde por correo.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "name",
         "email",
         "message",
         "consent"
        ],
        "properties": {
         "name": {
          "type": "string",
          "maxLength": 100,
          "description": "Nombre de la persona."
         },
         "email": {
          "type": "string",
          "format": "email",
          "maxLength": 254
         },
         "message": {
          "type": "string",
          "maxLength": 4000,
          "description": "Consulta en texto libre."
         },
         "consent": {
          "type": "boolean",
          "const": true,
          "description": "La persona aceptó el aviso de privacidad."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Consulta entregada",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "sent": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "message": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "message": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "message": {
           "type": "string"
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/api/chat": {
   "post": {
    "operationId": "conversar",
    "summary": "Conversa con el agente de bienvenida. Responde 503 si el agente no está activo.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "messages"
        ],
        "properties": {
         "messages": {
          "type": "array",
          "maxItems": 24,
          "items": {
           "type": "object",
           "required": [
            "role",
            "content"
           ],
           "properties": {
            "role": {
             "enum": [
              "user",
              "assistant"
             ]
            },
            "content": {
             "type": "string",
             "maxLength": 1000
            }
           }
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Respuesta del agente",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "reply": {
           "type": "string"
          },
          "proposal": {
           "type": "object",
           "description": "Consulta lista para confirmar y enviar con /api/contact.",
           "properties": {
            "name": {
             "type": "string"
            },
            "email": {
             "type": "string"
            },
            "message": {
             "type": "string"
            }
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "message": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "message": {
           "type": "string"
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "message": {
           "type": "string"
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/api/estado": {
   "get": {
    "operationId": "estado",
    "summary": "Indica si el agente de bienvenida está activo.",
    "responses": {
     "200": {
      "description": "Estado",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "agente": {
           "type": "boolean"
          }
         }
        }
       }
      }
     }
    }
   }
  }
 }
}