{
  "openapi": "3.1.0",
  "info": {
    "title": "Brotando API",
    "version": "1.0.0",
    "description": "API v1 de Brotando (brotando.es) para agentes IA: descubrimiento de silos y keywords, upsert de productos y creación/edición de BORRADORES de piezas.\n\n## Autenticación\nToken Sanctum vía `Authorization: Bearer <token>`. Cada endpoint exige una ability concreta (`pieces:write`, `products:write`); las lecturas de descubrimiento aceptan cualquier token válido. Sin token o con ability incorrecta: 401/403.\n\n## Reglas duras (D5/D7)\n- Ningún endpoint publica piezas: los estados alcanzables son solo `borrador`, `ia` y `revision`. La publicación siempre es humana (máx 2 piezas/día).\n- Los bloques con `type` desconocido devuelven 422 explícito; nunca se descartan en silencio.\n\n## Límites\n- `GET /pieces`: 100 resultados (orden `updated_at` desc).\n- `GET /keywords`: 25 resultados (orden `sv` desc).\n- `GET /products`: 50 resultados (orden `title`).\n\n## Nota de red\nCloudflare bloquea User-Agents genéricos (p. ej. `Python-urllib`) con error 1010: envía siempre un User-Agent propio (p. ej. `brotando-connect/1.0`).\n\n## Formato de bloques\n`blocks` es un array de payloads `{ \"type\": \"...\", \"data\": { ... } }`. Tipos válidos: `prosa`, `imagen`, `tabla_comparativa`, `quick_picks`, `mini_review`, `faq`, `oferta`.\n\n## Errores\nTodas las respuestas de error son JSON: `401` `{message}`, `403` `{message}`, `404` `{message}`, `422` `{message, errors}` con errores por campo.",
    "contact": {
      "email": "hola@brotando.es"
    }
  },
  "servers": [
    {
      "url": "https://api.brotando.es/v1",
      "description": "Producción, subdominio exclusivo"
    },
    {
      "url": "http://api.brotando.test/v1",
      "description": "Local"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Meta",
      "description": "Descubrimiento: silos, keywords y su estado de cobertura."
    },
    {
      "name": "Piezas",
      "description": "Borradores de contenido (hub, guías, artículos). Solo estados < listo."
    },
    {
      "name": "Productos",
      "description": "Catálogo de productos afiliados (upsert por ASIN) y precios verificados."
    }
  ],
  "paths": {
    "/sections": {
      "get": {
        "tags": [
          "Meta"
        ],
        "summary": "Silos (secciones) del site",
        "description": "Silos en orden de navegación, con indicador de si su pieza hub está publicada. Útil para elegir `section_slug` al crear piezas.",
        "operationId": "listSections",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de silos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Section"
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/sections/{slug}": {
      "patch": {
        "summary": "Actualizar presentación del silo (imagen de la card)",
        "description": "Establece o limpia la imagen del silo. La estructura del catálogo (slug, nombre, tono...) se gestiona en config/panel, no por API.",
        "security": [
          {
            "bearerAuth": [
              "sections:write"
            ]
          }
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Slug del silo (ver GET /sections)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SectionImageInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sección actualizada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SectionEnvelope"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/keywords": {
      "get": {
        "tags": [
          "Meta"
        ],
        "summary": "Keywords candidatas",
        "description": "Keywords ordenadas por volumen (`sv` desc), máx 25. `has_piece` indica si ya existe una pieza asociada (evitar canibalización).",
        "operationId": "listKeywords",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Búsqueda por substring en la keyword.",
            "schema": {
              "type": "string",
              "maxLength": 80
            }
          },
          {
            "name": "cluster",
            "in": "query",
            "description": "Filtro exacto por cluster.",
            "schema": {
              "type": "string",
              "maxLength": 40
            }
          },
          {
            "name": "priority",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "P1",
                "P2",
                "P3"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de keywords",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Keyword"
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/products": {
      "get": {
        "tags": [
          "Productos"
        ],
        "summary": "Buscar productos",
        "description": "Búsqueda por substring en título o ASIN, máx 50, orden alfabético por título.",
        "operationId": "listProducts",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Término aplicado a `title` y `asin`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de productos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Product"
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Productos"
        ],
        "summary": "Upsert de producto por ASIN",
        "description": "Crea el producto si el ASIN no existe; si existe, lo actualiza con los datos recibidos. Devuelve `201` al crear y `200` al actualizar.",
        "operationId": "upsertProduct",
        "security": [
          {
            "bearerAuth": [
              "products:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProductUpsertInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Producto creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProductEnvelope"
                }
              }
            }
          },
          "200": {
            "description": "Producto existente actualizado (mismo ASIN)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProductEnvelope"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/products/{product}/price": {
      "patch": {
        "tags": [
          "Productos"
        ],
        "summary": "Registrar precio verificado",
        "description": "Actualiza `price_current`, fija `price_verified_at` a hoy y registra un `price_check` con la fuente indicada (por defecto `agent`).",
        "operationId": "updateProductPrice",
        "security": [
          {
            "bearerAuth": [
              "products:write"
            ]
          }
        ],
        "parameters": [
          {
            "name": "product",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "ID del producto."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PriceUpdateInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Producto con el precio actualizado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProductEnvelope"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/pieces": {
      "get": {
        "tags": [
          "Piezas"
        ],
        "summary": "Listar piezas (borradores)",
        "description": "Últimas 100 piezas por `updated_at` desc, con su silo. Filtrable por estado. Nunca expone contenido de bloques: usa `GET /pieces/{id}`.",
        "operationId": "listPieces",
        "security": [
          {
            "bearerAuth": [
              "pieces:write"
            ]
          }
        ],
        "parameters": [
          {
            "name": "estado",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "borrador",
                "ia",
                "revision",
                "listo",
                "programado",
                "publicado"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de piezas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PieceSummary"
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      },
      "post": {
        "tags": [
          "Piezas"
        ],
        "summary": "Crear pieza (borrador)",
        "description": "Crea una pieza en estado `ia` por defecto (admite `borrador`, `ia`, `revision`; nunca `listo`+). El slug debe ser kebab-case y único dentro del silo. Un mismo `keyword_id` no puede repetirse entre piezas.",
        "operationId": "createPiece",
        "security": [
          {
            "bearerAuth": [
              "pieces:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PieceCreateInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Pieza creada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PieceEnvelope"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        }
      }
    },
    "/pieces/{piece}": {
      "get": {
        "tags": [
          "Piezas"
        ],
        "summary": "Detalle de pieza",
        "description": "Contenido completo: bloques en payload `{type, data}`, prosa y meta description.",
        "operationId": "showPiece",
        "security": [
          {
            "bearerAuth": [
              "pieces:write"
            ]
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PieceId"
          }
        ],
        "responses": {
          "200": {
            "description": "Detalle de la pieza",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PieceDetailEnvelope"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Piezas"
        ],
        "summary": "Editar pieza",
        "description": "Edición parcial. En `borrador`, `ia` o `revision` acepta también mover `estado` entre esos tres. En una pieza `publicado` admite ediciones de contenido en vivo (`title`, `prosa`, `meta_description`, `blocks`) sin tocar su estado; mandar `estado` responde `422` (bajar o retirar una pieza publicada se hace en el panel, para no dejar su URL en 404). En `listo` o `programado` responde `422`: usa el panel o `POST /pieces/{piece}/publish`.",
        "operationId": "updatePiece",
        "security": [
          {
            "bearerAuth": [
              "pieces:write"
            ]
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PieceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PieceUpdateInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pieza actualizada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PieceEnvelope"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "description": "Validación fallida, pieza en revisión humana (`listo`/`programado`) o intento de cambiar `estado` en una pieza publicada",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/ValidationError"
                    },
                    {
                      "$ref": "#/components/schemas/MessageError"
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/pieces/{piece}/publish": {
      "post": {
        "tags": [
          "Piezas"
        ],
        "summary": "Publicar pieza definitivamente",
        "description": "Publicación definitiva (D27). Exige `qa` con TODAS las comprobaciones del checklist marcadas (los mismos checkboxes que el panel). Requiere ability `pieces:publish`. Con cupo diario libre (máx. publicaciones/día, config del site) la pieza se publica y responde `estado: publicado`; sin cupo queda en cola (`estado: programado` con `programado_at` al próximo hueco) y el cron la publica automáticamente. La cache de página se invalida automáticamente.",
        "operationId": "publishPiece",
        "security": [
          {
            "bearerAuth": [
              "pieces:publish"
            ]
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PieceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PiecePublishInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pieza publicada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PiecePublishedEnvelope"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "description": "QA incompleto o pieza ya publicada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Token Sanctum personal, una ability mínima por token."
      }
    },
    "parameters": {
      "PieceId": {
        "name": "piece",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "ID de la pieza."
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Token ausente o inválido",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/MessageError"
            }
          }
        }
      },
      "Forbidden": {
        "description": "El token no tiene la ability requerida",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/MessageError"
            }
          }
        }
      },
      "NotFound": {
        "description": "Recurso inexistente",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/MessageError"
            }
          }
        }
      },
      "ValidationError": {
        "description": "Validación fallida",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ValidationError"
            }
          }
        }
      }
    },
    "schemas": {
      "Section": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "icon": {
            "type": "string",
            "description": "Emoji de identidad visual."
          },
          "tone": {
            "type": "string",
            "description": "Tono de paleta: moss, terra, lime, sun, bark."
          },
          "image_url": {
            "type": "string",
            "nullable": true,
            "maxLength": 500,
            "description": "URL de la imagen de la card del silo (p. ej. https://media.brotando.es/sitio/silos/{slug}.jpg, 16:7). Null = fondo tipográfico."
          },
          "summary": {
            "type": "string"
          },
          "hub_published": {
            "type": "boolean",
            "description": "true si la pieza hub del silo está publicada."
          }
        },
        "required": [
          "id",
          "slug",
          "name",
          "hub_published"
        ]
      },
      "Keyword": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "keyword": {
            "type": "string"
          },
          "sv": {
            "type": "integer",
            "description": "Volumen de búsqueda mensual."
          },
          "kd": {
            "type": "integer",
            "description": "Dificultad estimada."
          },
          "cluster": {
            "type": "string"
          },
          "intent": {
            "type": "string"
          },
          "priority": {
            "type": "string",
            "enum": [
              "P1",
              "P2",
              "P3"
            ]
          },
          "suggested_title": {
            "type": "string",
            "nullable": true
          },
          "has_piece": {
            "type": "boolean",
            "description": "true si ya existe una pieza asociada a esta keyword."
          }
        },
        "required": [
          "id",
          "keyword",
          "sv",
          "kd",
          "has_piece"
        ]
      },
      "Product": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "asin": {
            "type": "string",
            "minLength": 10,
            "maxLength": 10
          },
          "title": {
            "type": "string"
          },
          "brand": {
            "type": "string",
            "nullable": true
          },
          "price_current": {
            "type": "number",
            "format": "float",
            "nullable": true
          },
          "price_verified_at": {
            "type": "string",
            "format": "date",
            "nullable": true
          }
        },
        "required": [
          "id",
          "asin",
          "title"
        ]
      },
      "ProductUpsertInput": {
        "type": "object",
        "properties": {
          "asin": {
            "type": "string",
            "minLength": 10,
            "maxLength": 10
          },
          "title": {
            "type": "string",
            "maxLength": 255
          },
          "brand": {
            "type": "string",
            "maxLength": 80
          },
          "measures": {
            "type": "string",
            "maxLength": 120
          },
          "best_for": {
            "type": "string",
            "maxLength": 160
          },
          "specs": {
            "type": "object",
            "additionalProperties": true,
            "description": "Specificaciones libres clave-valor."
          },
          "price_current": {
            "type": "number",
            "format": "float",
            "minimum": 0
          },
          "price_verified_at": {
            "type": "string",
            "format": "date"
          }
        },
        "required": [
          "asin",
          "title"
        ]
      },
      "PriceUpdateInput": {
        "type": "object",
        "properties": {
          "price_current": {
            "type": "number",
            "format": "float",
            "minimum": 0
          },
          "source": {
            "type": "string",
            "enum": [
              "manual",
              "pa-api",
              "agent"
            ],
            "default": "agent"
          }
        },
        "required": [
          "price_current"
        ]
      },
      "PieceSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "section": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer"
              },
              "slug": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "section_id": {
            "type": "integer"
          },
          "template": {
            "$ref": "#/components/schemas/PieceTemplate"
          },
          "slug": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "estado": {
            "$ref": "#/components/schemas/PieceEstado"
          },
          "keyword_id": {
            "type": "integer",
            "nullable": true
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "template",
          "slug",
          "title",
          "estado"
        ]
      },
      "PieceEnvelope": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/Piece"
          }
        },
        "required": [
          "data"
        ]
      },
      "PieceDetailEnvelope": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/PieceDetail"
          }
        },
        "required": [
          "data"
        ]
      },
      "ProductEnvelope": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/Product"
          }
        },
        "required": [
          "data"
        ]
      },
      "Piece": {
        "type": "object",
        "description": "Pieza tras crear/editar (modelo completo con su silo).",
        "properties": {
          "id": {
            "type": "integer"
          },
          "section": {
            "$ref": "#/components/schemas/SectionRef"
          },
          "section_id": {
            "type": "integer"
          },
          "template": {
            "$ref": "#/components/schemas/PieceTemplate"
          },
          "slug": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "estado": {
            "$ref": "#/components/schemas/PieceEstado"
          },
          "keyword_id": {
            "type": "integer",
            "nullable": true
          },
          "author_id": {
            "type": "integer",
            "nullable": true
          },
          "blocks": {
            "type": "array",
            "nullable": true,
            "items": {
              "$ref": "#/components/schemas/BlockPayload"
            }
          },
          "prosa": {
            "type": "string",
            "nullable": true
          },
          "meta_title": {
            "type": "string",
            "nullable": true
          },
          "meta_description": {
            "type": "string",
            "nullable": true
          },
          "noindex": {
            "type": "boolean"
          },
          "programado_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "publicado_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "qa": {
            "type": "object",
            "additionalProperties": true,
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "template",
          "slug",
          "title",
          "estado"
        ]
      },
      "PieceDetail": {
        "type": "object",
        "description": "Contenido completo de la pieza, formato pensado para agentes.",
        "properties": {
          "id": {
            "type": "integer"
          },
          "section": {
            "$ref": "#/components/schemas/SectionRef"
          },
          "keyword": {
            "type": "object",
            "nullable": true,
            "properties": {
              "id": {
                "type": "integer"
              },
              "keyword": {
                "type": "string"
              }
            }
          },
          "template": {
            "$ref": "#/components/schemas/PieceTemplate"
          },
          "slug": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "estado": {
            "$ref": "#/components/schemas/PieceEstado"
          },
          "blocks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BlockPayload"
            }
          },
          "prosa": {
            "type": "string",
            "nullable": true
          },
          "meta_description": {
            "type": "string",
            "nullable": true
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "template",
          "slug",
          "title",
          "estado",
          "blocks"
        ]
      },
      "SectionRef": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      },
      "PieceTemplate": {
        "type": "string",
        "enum": [
          "hub_categoria",
          "guia_compra",
          "articulo_categoria",
          "vs",
          "info_soporte",
          "ofertas"
        ]
      },
      "PieceEstado": {
        "type": "string",
        "description": "La API solo fija borrador/ia/revision; listo+ lo gestiona el humano.",
        "enum": [
          "borrador",
          "ia",
          "revision",
          "listo",
          "programado",
          "publicado"
        ]
      },
      "PieceCreateInput": {
        "type": "object",
        "properties": {
          "section_slug": {
            "type": "string",
            "description": "Slug de un silo existente (ver GET /sections)."
          },
          "template": {
            "$ref": "#/components/schemas/PieceTemplate"
          },
          "slug": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$",
            "description": "Kebab-case; único dentro del silo."
          },
          "title": {
            "type": "string",
            "maxLength": 255
          },
          "keyword_id": {
            "type": "integer",
            "nullable": true,
            "description": "Keyword a cubrir; una keyword solo puede usarse en una pieza."
          },
          "prosa": {
            "type": "string"
          },
          "meta_description": {
            "type": "string",
            "maxLength": 160
          },
          "blocks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BlockPayload"
            }
          },
          "estado": {
            "type": "string",
            "enum": [
              "borrador",
              "ia",
              "revision"
            ],
            "default": "ia"
          }
        },
        "required": [
          "section_slug",
          "template",
          "slug",
          "title"
        ]
      },
      "PieceUpdateInput": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "maxLength": 255
          },
          "prosa": {
            "type": "string",
            "nullable": true
          },
          "meta_description": {
            "type": "string",
            "maxLength": 160
          },
          "blocks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BlockPayload"
            }
          },
          "estado": {
            "type": "string",
            "description": "Solo en piezas no publicadas. Si la pieza está `publicado`, mandar `estado` responde `422`: el estado de una pieza publicada se cambia desde el panel.",
            "enum": [
              "borrador",
              "ia",
              "revision"
            ]
          }
        }
      },
      "BlockPayload": {
        "type": "object",
        "description": "Bloque de contenido. `type` debe ser uno de los registrados; un tipo desconocido devuelve 422.",
        "required": [
          "type",
          "data"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "prosa",
              "imagen",
              "tabla_comparativa",
              "quick_picks",
              "mini_review",
              "faq",
              "oferta"
            ]
          },
          "data": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ProsaData"
              },
              {
                "$ref": "#/components/schemas/ImagenData"
              },
              {
                "$ref": "#/components/schemas/TablaComparativaData"
              },
              {
                "$ref": "#/components/schemas/QuickPicksData"
              },
              {
                "$ref": "#/components/schemas/MiniReviewData"
              },
              {
                "$ref": "#/components/schemas/FaqData"
              },
              {
                "$ref": "#/components/schemas/OfertaData"
              }
            ]
          }
        }
      },
      "ProsaData": {
        "type": "object",
        "properties": {
          "heading": {
            "type": "string",
            "nullable": true
          },
          "content": {
            "type": "string"
          }
        }
      },
      "ImagenData": {
        "type": "object",
        "properties": {
          "mediaUuid": {
            "type": "string",
            "nullable": true,
            "description": "UUID de media en la librería (spatie media library); opcional."
          },
          "url": {
            "type": "string",
            "nullable": true,
            "description": "URL pública de la imagen en el bucket de media (media.brotando.es, p. ej. piezas/{silo}/{slug}/foto-0.webp). Alterna a mediaUuid para la ingesta por API."
          },
          "alt": {
            "type": "string"
          },
          "caption": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "TablaComparativaData": {
        "type": "object",
        "properties": {
          "productIds": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "intro": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "QuickPicksData": {
        "type": "object",
        "properties": {
          "picks": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "productId": {
                  "type": "integer"
                },
                "label": {
                  "type": "string"
                }
              },
              "required": [
                "productId",
                "label"
              ]
            }
          }
        }
      },
      "MiniReviewData": {
        "type": "object",
        "properties": {
          "productId": {
            "type": "integer",
            "nullable": true
          },
          "prose": {
            "type": "string"
          }
        }
      },
      "FaqData": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "question": {
                  "type": "string"
                },
                "answer": {
                  "type": "string"
                }
              },
              "required": [
                "question",
                "answer"
              ]
            }
          }
        }
      },
      "OfertaData": {
        "type": "object",
        "properties": {
          "productId": {
            "type": "integer",
            "nullable": true
          },
          "priceBefore": {
            "type": "number",
            "format": "float",
            "nullable": true
          },
          "priceNow": {
            "type": "number",
            "format": "float",
            "nullable": true
          },
          "expiresAt": {
            "type": "string",
            "format": "date",
            "nullable": true
          },
          "note": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "MessageError": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          }
        },
        "required": [
          "message"
        ]
      },
      "ValidationError": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          },
          "errors": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "required": [
          "message",
          "errors"
        ]
      },
      "PiecePublishInput": {
        "type": "object",
        "description": "Checklist QA completo. Se acepta mapa {clave: true} o lista de claves.",
        "required": [
          "qa"
        ],
        "properties": {
          "qa": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "no_reproducible_por_ia": {
                    "type": "boolean",
                    "description": "Foto propia, medición o dato de uso real no reproducible por IA"
                  },
                  "datos_verificados": {
                    "type": "boolean",
                    "description": "Tabla/datos con specs del listing y precio con fecha"
                  },
                  "primer_parrafo_query": {
                    "type": "boolean",
                    "description": "El primer párrafo responde la query"
                  },
                  "links_ok": {
                    "type": "boolean",
                    "description": "Los links funcionan y apuntan al producto correcto"
                  },
                  "titulo_60": {
                    "type": "boolean",
                    "description": "Título < 60 caracteres"
                  },
                  "meta_description": {
                    "type": "boolean",
                    "description": "Meta description con CTA implícito"
                  }
                },
                "required": [
                  "no_reproducible_por_ia",
                  "datos_verificados",
                  "primer_parrafo_query",
                  "links_ok",
                  "titulo_60",
                  "meta_description"
                ]
              },
              {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "no_reproducible_por_ia",
                    "datos_verificados",
                    "primer_parrafo_query",
                    "links_ok",
                    "titulo_60",
                    "meta_description"
                  ]
                },
                "minItems": 6,
                "uniqueItems": true
              }
            ]
          }
        }
      },
      "PiecePublishedEnvelope": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer"
              },
              "section": {
                "$ref": "#/components/schemas/SectionRef"
              },
              "template": {
                "$ref": "#/components/schemas/PieceTemplate"
              },
              "slug": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "estado": {
                "type": "string",
                "enum": [
                  "publicado",
                  "programado"
                ],
                "description": "publicado = en línea ahora; programado = en cola por cupo diario, el cron la publicará"
              },
              "publicado_at": {
                "type": "string",
                "format": "date-time"
              },
              "public_url": {
                "type": "string",
                "nullable": true
              },
              "qa": {
                "type": "object",
                "additionalProperties": {
                  "type": "boolean"
                }
              },
              "programado_at": {
                "type": "string",
                "format": "date-time",
                "nullable": true,
                "description": "Fecha de publicación en cola (solo si estado=programado)"
              }
            },
            "required": [
              "id",
              "section",
              "template",
              "slug",
              "title",
              "estado",
              "publicado_at",
              "public_url",
              "qa"
            ]
          },
          "message": {
            "type": "string",
            "description": "Resultado de la operación: publicada o en cola por cupo diario alcanzado"
          }
        },
        "required": [
          "data"
        ]
      },
      "SectionImageInput": {
        "type": "object",
        "properties": {
          "image_url": {
            "type": "string",
            "nullable": true,
            "maxLength": 500,
            "description": "URL http/https de la imagen. Enviar null para volver al fondo tipográfico."
          }
        }
      },
      "SectionEnvelope": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/Section"
          }
        }
      }
    }
  }
}
