{
  "openapi": "3.1.1",
  "jsonSchemaDialect": "https://spec.openapis.org/oas/3.1/dialect/base",
  "info": {
    "title": "API de mireforma.net",
    "version": "1.1.0",
    "summary": "Normativa municipal, catálogo de tarifas, directorio de empresas y presupuesto de reforma por partidas.",
    "description": "API abierta de mireforma.net. Las rutas públicas no piden cuenta, admiten CORS y devuelven datos con fuente oficial.\n\nLímites: 60 peticiones por minuto e IP en las rutas públicas (30 en el validador de planos), con las cabeceras RateLimit y RateLimit-Policy (draft-ietf-httpapi-ratelimit-headers) y 429 con Retry-After al pasarse.\n\nDatos bajo licencia CC BY 4.0: cita «mireforma.net» con enlace. Los PDF y fotos de fabricantes no se republican: cada precio enlaza su documento oficial. El directorio no publica teléfonos ni correos.\n\nPresupuestos en FIEBDC-3 (.bc3) para Presto, Arquímedes, CYPE o TCQ; planos desde Magicplan, IFC, DXF y Planner 5D.\n\nRutas de proyecto: OAuth 2.1 con PKCE (descubrimiento en /.well-known/oauth-authorization-server, RFC 8414) o token personal de /cuenta.",
    "termsOfService": "https://mireforma.net/terminos",
    "contact": {
      "name": "mireforma.net",
      "url": "https://mireforma.net/contacto"
    },
    "license": {
      "name": "CC BY 4.0",
      "identifier": "CC-BY-4.0"
    }
  },
  "externalDocs": {
    "description": "Guía para desarrolladores, MCP y WebMCP",
    "url": "https://mireforma.net/desarrolladores"
  },
  "servers": [
    {
      "url": "https://mireforma.net",
      "description": "Producción"
    }
  ],
  "tags": [
    {
      "name": "Presupuesto",
      "description": "Presupuesto por embudo de decisiones: estancia y m² → material o referencia → proveedor."
    },
    {
      "name": "Catálogo",
      "description": "Tarifas oficiales de fabricantes (PVP o tarifa sin IVA) con enlace al documento original."
    },
    {
      "name": "Directorio",
      "description": "Distribuidores e instaladores (solo empresas, sin teléfonos ni correos)."
    },
    {
      "name": "Municipios",
      "description": "ICIO, tasa, sede, urbanismo y habitabilidad por código INE."
    },
    {
      "name": "Planos",
      "description": "Validación de planos y formatos de entrada."
    },
    {
      "name": "Proyecto",
      "description": "Rutas de la cuenta: exportar e importar presupuesto y plano."
    }
  ],
  "paths": {
    "/api/catalogo": {
      "get": {
        "security": [],
        "tags": [
          "Catálogo"
        ],
        "operationId": "buscarCatalogo",
        "summary": "Buscar referencias del catálogo",
        "parameters": [
          {
            "name": "marca",
            "in": "query",
            "description": "Id o nombre de marca (roca, legrand…)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "familia",
            "in": "query",
            "description": "Familia (griferia, electricidad, banos…)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "ref",
            "in": "query",
            "description": "Referencia exacta del fabricante",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "Texto libre",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "precio_min",
            "in": "query",
            "description": "Precio mínimo sin IVA",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "precio_max",
            "in": "query",
            "description": "Precio máximo sin IVA",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "limite",
            "in": "query",
            "description": "Máximo de resultados",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            }
          },
          {
            "name": "offset",
            "in": "query",
            "description": "Desplazamiento",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Referencias con precio, tipo de precio, vigencia y enlace oficial",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Generico"
                }
              }
            }
          },
          "400": {
            "description": "Filtro no válido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      }
    },
    "/api/directorio": {
      "get": {
        "security": [],
        "tags": [
          "Directorio"
        ],
        "operationId": "buscarDirectorio",
        "summary": "Distribuidores e instaladores por categoría, marca y zona",
        "parameters": [
          {
            "name": "categoria",
            "in": "query",
            "description": "Categoría o familia",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "marca",
            "in": "query",
            "description": "Marca que distribuyen o instalan",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "ine",
            "in": "query",
            "description": "Municipio INE (5 dígitos)",
            "schema": {
              "type": "string",
              "pattern": "^\\d{5}$"
            }
          },
          {
            "name": "provincia",
            "in": "query",
            "description": "Provincia INE (2 dígitos)",
            "schema": {
              "type": "string",
              "pattern": "^\\d{2}$"
            }
          },
          {
            "name": "ccaa",
            "in": "query",
            "description": "Comunidad autónoma",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limite",
            "in": "query",
            "description": "Máximo",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Empresas ordenadas por cercanía (municipio, provincia, comunidad)",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Generico"
                }
              }
            }
          },
          "400": {
            "description": "Filtro no válido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      }
    },
    "/api/presupuesto/calcular": {
      "get": {
        "security": [],
        "tags": [
          "Presupuesto"
        ],
        "operationId": "calcularPresupuestoGet",
        "summary": "Presupuesto de una estancia (atajo GET)",
        "parameters": [
          {
            "name": "tipo",
            "in": "query",
            "description": "Tipo de estancia",
            "schema": {
              "type": "string",
              "enum": [
                "bano",
                "cocina",
                "dormitorio",
                "salon",
                "paso",
                "trabajo",
                "servicio"
              ]
            }
          },
          {
            "name": "m2",
            "in": "query",
            "description": "Superficie en m²",
            "schema": {
              "type": "number",
              "exclusiveMinimum": 0,
              "maximum": 500
            }
          },
          {
            "name": "ine",
            "in": "query",
            "description": "Municipio: INE o nombre",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "elige",
            "in": "query",
            "description": "concepto:marca[:referencia[:precio]] (repetible)",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "style": "form",
            "explode": true
          },
          {
            "name": "materiales",
            "in": "query",
            "description": "Quién compra los materiales",
            "schema": {
              "type": "string",
              "enum": [
                "propietario",
                "empresa"
              ]
            }
          },
          {
            "name": "formato",
            "in": "query",
            "description": "json (defecto), csv o bc3 (FIEBDC-3, Windows-1252)",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "csv",
                "bc3"
              ],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Presupuesto con líneas, PEM, IVA, ICIO y fuentes",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Presupuesto"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              },
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "contentMediaType": "application/octet-stream",
                  "description": "Fichero .bc3 FIEBDC-3/2024 (~V, ~K, ~C, ~D, ~M, ~T), juego de caracteres ANSI"
                }
              }
            }
          },
          "400": {
            "description": "Petición no válida",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      },
      "post": {
        "security": [],
        "tags": [
          "Presupuesto"
        ],
        "operationId": "calcularPresupuesto",
        "summary": "Presupuesto por embudo de decisiones",
        "parameters": [
          {
            "name": "formato",
            "in": "query",
            "description": "json (defecto), csv o bc3 (FIEBDC-3, Windows-1252)",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "csv",
                "bc3"
              ],
              "default": "json"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PeticionPresupuesto"
              },
              "example": {
                "estancias": [
                  {
                    "tipo": "bano",
                    "superficie": 5,
                    "elecciones": {
                      "inodoro": {
                        "marca": "roca"
                      }
                    }
                  }
                ],
                "ine": "08019"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Presupuesto con líneas, PEM, IVA, ICIO y fuentes",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Presupuesto"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              },
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "contentMediaType": "application/octet-stream",
                  "description": "Fichero .bc3 FIEBDC-3/2024 (~V, ~K, ~C, ~D, ~M, ~T), juego de caracteres ANSI"
                }
              }
            }
          },
          "400": {
            "description": "Petición no válida",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      }
    },
    "/api/lista-compra/calcular": {
      "post": {
        "security": [],
        "tags": [
          "Presupuesto"
        ],
        "operationId": "calcularListaCompra",
        "summary": "Lista de compra y dónde comprar cada producto",
        "parameters": [
          {
            "name": "formato",
            "in": "query",
            "description": "json o csv",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "csv"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/PeticionPresupuesto"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "provincia": {
                        "type": "string",
                        "pattern": "^\\d{2}$"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Productos agrupados, cantidades con merma, precios y proveedores",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Generico"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Petición no válida",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      },
      "get": {
        "security": [],
        "tags": [
          "Presupuesto"
        ],
        "operationId": "calcularListaCompraGet",
        "summary": "Lista de compra de una estancia (atajo GET)",
        "parameters": [
          {
            "name": "tipo",
            "in": "query",
            "description": "Tipo de estancia",
            "schema": {
              "type": "string",
              "enum": [
                "bano",
                "cocina",
                "dormitorio",
                "salon",
                "paso",
                "trabajo",
                "servicio"
              ]
            }
          },
          {
            "name": "m2",
            "in": "query",
            "description": "Superficie",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "ine",
            "in": "query",
            "description": "Municipio",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "provincia",
            "in": "query",
            "description": "Provincia (2 dígitos)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "formato",
            "in": "query",
            "description": "json o csv",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "csv"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de compra",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Generico"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Petición no válida",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      }
    },
    "/api/presupuesto/opciones": {
      "get": {
        "security": [],
        "tags": [
          "Presupuesto"
        ],
        "operationId": "opcionesConcepto",
        "summary": "Opciones de nivel 2 para un concepto, de la más barata a la más cara",
        "parameters": [
          {
            "name": "concepto",
            "in": "query",
            "description": "Concepto del presupuesto",
            "schema": {
              "type": "string",
              "enum": [
                "demolicion",
                "residuos",
                "fontaneria",
                "impermeabilizacion",
                "electricidad",
                "alicatado",
                "solado",
                "plato-ducha",
                "mampara",
                "inodoro",
                "lavabo",
                "grifo-lavabo",
                "grifo-ducha",
                "grifo-cocina",
                "cocina-mobiliario",
                "pintura"
              ]
            },
            "required": true
          },
          {
            "name": "marca",
            "in": "query",
            "description": "Id de marca",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limite",
            "in": "query",
            "description": "Máximo 50",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Opciones con precio, marca y enlace oficial",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Generico"
                }
              }
            }
          },
          "400": {
            "description": "Concepto desconocido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      }
    },
    "/api/municipios": {
      "get": {
        "security": [],
        "tags": [
          "Municipios"
        ],
        "operationId": "buscarMunicipios",
        "summary": "Buscar municipios por nombre",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Nombre o parte del nombre",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "provincia",
            "in": "query",
            "description": "Provincia INE (2 dígitos)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limite",
            "in": "query",
            "description": "Máximo 100",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Municipios con su código INE y ficha",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Generico"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      }
    },
    "/api/municipios/{ine}": {
      "get": {
        "security": [],
        "tags": [
          "Municipios"
        ],
        "operationId": "normativaMunicipio",
        "summary": "Normativa de reforma de un municipio",
        "parameters": [
          {
            "name": "ine",
            "in": "path",
            "required": true,
            "description": "Código INE de 5 dígitos",
            "schema": {
              "type": "string",
              "pattern": "^\\d{5}$"
            },
            "example": "08019"
          }
        ],
        "responses": {
          "200": {
            "description": "ICIO, tasa, sede, urbanismo, habitabilidad, zona climática y reglas aplicables",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Municipio"
                }
              }
            }
          },
          "404": {
            "description": "INE desconocido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      }
    },
    "/api/validar-plano": {
      "get": {
        "security": [],
        "tags": [
          "Planos"
        ],
        "operationId": "validadorDescriptor",
        "summary": "Formatos, ejemplos y versión de reglas del validador",
        "responses": {
          "200": {
            "description": "Descriptor",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Generico"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      },
      "post": {
        "security": [],
        "tags": [
          "Planos"
        ],
        "operationId": "validarPlano",
        "summary": "Validar un plano contra CTE, habitabilidad y ordenanza; trámite y documentos",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PeticionValidar"
              },
              "example": {
                "ejemplo": "bcn_piso_redistribucion"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resultados por regla con su norma, y trámite",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Generico"
                }
              }
            }
          },
          "400": {
            "description": "Plano no válido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Fichero > 20 MB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Formato no soportado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Fichero ilegible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      }
    },
    "/api/validar-plano/esquema": {
      "get": {
        "security": [],
        "tags": [
          "Planos"
        ],
        "operationId": "esquemaPlano",
        "summary": "JSON Schema de mireforma-plano/1",
        "responses": {
          "200": {
            "description": "JSON Schema",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      }
    },
    "/api/validar-plano/ejemplos/{id}": {
      "get": {
        "security": [],
        "tags": [
          "Planos"
        ],
        "operationId": "ejemploPlano",
        "summary": "Plano de ejemplo",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "bcn_piso_redistribucion"
          }
        ],
        "responses": {
          "200": {
            "description": "Plano mireforma-plano/1",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Generico"
                }
              }
            }
          },
          "404": {
            "description": "Ejemplo desconocido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/Limite"
          }
        }
      }
    },
    "/api/proyecto/presupuesto-estimado": {
      "get": {
        "security": [
          {
            "oauth2": [
              "reforma"
            ]
          },
          {
            "tokenPersonal": []
          }
        ],
        "tags": [
          "Proyecto"
        ],
        "operationId": "presupuestoProyecto",
        "summary": "Presupuesto estimado del proyecto (JSON, CSV o BC3)",
        "parameters": [
          {
            "name": "ine",
            "in": "query",
            "description": "Municipio (si no está guardado en ajustes)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "materiales",
            "in": "query",
            "description": "propietario o empresa",
            "schema": {
              "type": "string",
              "enum": [
                "propietario",
                "empresa"
              ]
            }
          },
          {
            "name": "formato",
            "in": "query",
            "description": "json (defecto), csv o bc3 (FIEBDC-3, Windows-1252)",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "csv",
                "bc3"
              ],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Presupuesto del proyecto por capítulos (estancias)",
            "headers": {
              "RateLimit": {
                "$ref": "#/components/headers/RateLimit"
              },
              "RateLimit-Policy": {
                "$ref": "#/components/headers/RateLimitPolicy"
              },
              "Link": {
                "$ref": "#/components/headers/LinkLicencia"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Presupuesto"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              },
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "contentMediaType": "application/octet-stream",
                  "description": "Fichero .bc3 FIEBDC-3/2024 (~V, ~K, ~C, ~D, ~M, ~T), juego de caracteres ANSI"
                }
              }
            }
          },
          "400": {
            "description": "Petición no válida",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Sin sesión o token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/proyecto/importar-bc3": {
      "post": {
        "security": [
          {
            "oauth2": [
              "reforma"
            ]
          },
          {
            "tokenPersonal": []
          }
        ],
        "tags": [
          "Proyecto"
        ],
        "operationId": "importarBc3",
        "summary": "Importar partidas y precios de un .bc3 al proyecto",
        "description": "Crea partidas de obra (capítulo, código, unidad, medición, texto) y, por cada precio, una opción que no se elige sola. No borra nada; repetir la importación no duplica partidas.",
        "parameters": [
          {
            "name": "dry_run",
            "in": "query",
            "description": "true: solo informa",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "nombre",
            "in": "query",
            "description": "Nombre del fichero (cuerpo binario)",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PeticionBc3"
              }
            },
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "contentMediaType": "application/octet-stream"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resumen de la importación",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResultadoImportacion"
                }
              }
            }
          },
          "400": {
            "description": "Fichero no válido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Sin sesión o token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Demasiado grande",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "No es FIEBDC-3",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/proyecto/importar-plano": {
      "post": {
        "security": [
          {
            "oauth2": [
              "reforma"
            ]
          },
          {
            "tokenPersonal": []
          }
        ],
        "tags": [
          "Proyecto"
        ],
        "operationId": "importarPlano",
        "summary": "Importar estancias y m² desde Magicplan, IFC, DXF o Planner 5D",
        "description": "Formatos: magicplan-api, magicplan-csv, ifc, dxf, planner5d, mireforma-plano/1. Crea las estancias que faltan; con actualizar=true corrige m² y tipo de las que ya existen. Nunca borra.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PeticionPlano"
              },
              "example": {
                "fichero": {
                  "nombre": "room-list.csv",
                  "texto": "Room;Floor;Area (m²);Height (m)\nBathroom;Ground floor;3,9;2,5"
                },
                "dry_run": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Plan o resultado de la importación",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResultadoImportacion"
                }
              }
            }
          },
          "400": {
            "description": "Entrada no válida",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Sin sesión o token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Formato no soportado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Sin estancias",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/proyecto/importar-plano/remoto": {
      "post": {
        "security": [
          {
            "oauth2": [
              "reforma"
            ]
          },
          {
            "tokenPersonal": []
          }
        ],
        "tags": [
          "Proyecto"
        ],
        "operationId": "importarPlanoRemoto",
        "summary": "Traer el plano de Magicplan o Planner 5D con tu propia clave",
        "description": "Opcional: solo si el despliegue lo habilita (INTEGRACIONES_REMOTAS). La clave viaja en la petición, no se guarda ni se registra. Magicplan pide plan PRO/API del workspace; Planner 5D, cuenta con acceso comercial/PRO.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PeticionPlanoRemoto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resultado de la importación",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResultadoImportacion"
                }
              }
            }
          },
          "400": {
            "description": "Faltan datos",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Sin sesión o token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "501": {
            "description": "Conector no habilitado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "El servicio remoto falló",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "oauth2": {
        "type": "oauth2",
        "description": "OAuth 2.1: código de autorización con PKCE S256 y registro dinámico de clientes (RFC 7591).",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://mireforma.net/oauth/authorize",
            "tokenUrl": "https://mireforma.net/oauth/token",
            "refreshUrl": "https://mireforma.net/oauth/token",
            "scopes": {
              "reforma": "Leer y editar tu reforma"
            }
          }
        }
      },
      "tokenPersonal": {
        "type": "http",
        "scheme": "bearer",
        "description": "Token personal creado en /cuenta"
      }
    },
    "headers": {
      "RateLimit": {
        "description": "Cuota restante (draft-ietf-httpapi-ratelimit-headers)",
        "schema": {
          "type": "string"
        }
      },
      "RateLimitPolicy": {
        "description": "Política de cuota",
        "schema": {
          "type": "string"
        }
      },
      "LinkLicencia": {
        "description": "Licencia de los datos (RFC 8288, rel=\"license\")",
        "schema": {
          "type": "string"
        },
        "example": "<https://creativecommons.org/licenses/by/4.0/>; rel=\"license\""
      }
    },
    "responses": {
      "Limite": {
        "description": "Demasiadas peticiones",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "integer"
            }
          },
          "RateLimit": {
            "$ref": "#/components/headers/RateLimit"
          },
          "RateLimit-Policy": {
            "$ref": "#/components/headers/RateLimitPolicy"
          },
          "Link": {
            "$ref": "#/components/headers/LinkLicencia"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "mensaje": {
            "type": "string"
          },
          "ruta": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      },
      "Generico": {
        "type": "object",
        "additionalProperties": true
      },
      "Eleccion": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "marca": {
            "type": "string"
          },
          "ref": {
            "type": "string"
          },
          "material": {
            "type": "string"
          },
          "proveedor": {
            "type": "string"
          },
          "precio_proveedor": {
            "type": "number",
            "minimum": 0
          }
        }
      },
      "EstanciaPeticion": {
        "type": "object",
        "required": [
          "tipo",
          "superficie"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "nombre": {
            "type": "string"
          },
          "tipo": {
            "type": "string",
            "enum": [
              "bano",
              "cocina",
              "dormitorio",
              "salon",
              "paso",
              "trabajo",
              "servicio"
            ]
          },
          "superficie": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 500
          },
          "elecciones": {
            "type": "object",
            "propertyNames": {
              "enum": [
                "demolicion",
                "residuos",
                "fontaneria",
                "impermeabilizacion",
                "electricidad",
                "alicatado",
                "solado",
                "plato-ducha",
                "mampara",
                "inodoro",
                "lavabo",
                "grifo-lavabo",
                "grifo-ducha",
                "grifo-cocina",
                "cocina-mobiliario",
                "pintura"
              ]
            },
            "additionalProperties": {
              "$ref": "#/components/schemas/Eleccion"
            }
          },
          "partidas": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "clave"
              ],
              "properties": {
                "clave": {
                  "type": "string",
                  "enum": [
                    "demolicion",
                    "residuos",
                    "fontaneria",
                    "impermeabilizacion",
                    "electricidad",
                    "alicatado",
                    "solado",
                    "plato-ducha",
                    "mampara",
                    "inodoro",
                    "lavabo",
                    "grifo-lavabo",
                    "grifo-ducha",
                    "grifo-cocina",
                    "cocina-mobiliario",
                    "pintura"
                  ]
                },
                "cantidad": {
                  "type": "number"
                },
                "marca": {
                  "type": "string"
                },
                "ref": {
                  "type": "string"
                },
                "precio_proveedor": {
                  "type": "number"
                }
              }
            }
          }
        }
      },
      "PeticionPresupuesto": {
        "type": "object",
        "properties": {
          "estancias": {
            "type": "array",
            "maxItems": 40,
            "items": {
              "$ref": "#/components/schemas/EstanciaPeticion"
            }
          },
          "tipo": {
            "type": "string",
            "enum": [
              "bano",
              "cocina",
              "dormitorio",
              "salon",
              "paso",
              "trabajo",
              "servicio"
            ]
          },
          "m2": {
            "type": "number"
          },
          "ine": {
            "type": "string",
            "description": "INE o nombre del municipio"
          },
          "materiales": {
            "type": "string",
            "enum": [
              "propietario",
              "empresa"
            ]
          },
          "vivienda_mas_2_anios": {
            "type": "boolean"
          },
          "formato": {
            "type": "string",
            "enum": [
              "json",
              "csv",
              "bc3"
            ]
          }
        }
      },
      "Presupuesto": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "lineas",
          "totales"
        ],
        "properties": {
          "municipio": {
            "type": [
              "object",
              "null"
            ]
          },
          "estancias": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "lineas": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "clave": {
                  "type": "string"
                },
                "concepto": {
                  "type": "string"
                },
                "estancia": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "unidad": {
                  "type": "string"
                },
                "cantidad": {
                  "type": "number"
                },
                "nivel": {
                  "type": "integer",
                  "enum": [
                    1,
                    2,
                    3
                  ]
                },
                "estimado": {
                  "type": "number"
                }
              }
            }
          },
          "totales": {
            "type": "object"
          },
          "aviso": {
            "type": "string"
          }
        }
      },
      "Municipio": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "ine",
          "municipio"
        ],
        "properties": {
          "ine": {
            "type": "string"
          },
          "municipio": {
            "type": "string"
          },
          "provincia": {
            "type": "string"
          },
          "ccaa": {
            "type": "string"
          },
          "ficha": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "icio": {
            "type": "object"
          },
          "tasa_licencia": {
            "type": "string"
          },
          "sede_electronica": {
            "type": [
              "string",
              "null"
            ]
          },
          "urbanismo": {
            "type": "object"
          },
          "habitabilidad": {
            "type": "object"
          },
          "zona_climatica": {
            "type": [
              "object",
              "null"
            ]
          },
          "licencia": {
            "type": "object"
          }
        }
      },
      "Fichero": {
        "type": "object",
        "required": [
          "nombre"
        ],
        "properties": {
          "nombre": {
            "type": "string"
          },
          "base64": {
            "type": "string",
            "contentEncoding": "base64"
          },
          "texto": {
            "type": "string"
          }
        }
      },
      "PeticionValidar": {
        "type": "object",
        "properties": {
          "ejemplo": {
            "type": "string"
          },
          "plano": {
            "type": "object"
          },
          "fichero": {
            "$ref": "#/components/schemas/Fichero"
          },
          "ine": {
            "type": "string",
            "pattern": "^\\d{5}$"
          },
          "formato_entrada": {
            "type": "string",
            "enum": [
              "mireforma-plano/1",
              "magicplan-api",
              "magicplan-csv",
              "ifc",
              "dxf"
            ]
          },
          "obras": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "detalle": {
            "type": "string",
            "enum": [
              "resumen",
              "completo"
            ]
          }
        }
      },
      "PeticionBc3": {
        "type": "object",
        "required": [
          "fichero"
        ],
        "properties": {
          "fichero": {
            "$ref": "#/components/schemas/Fichero"
          },
          "dry_run": {
            "type": "boolean",
            "default": false
          },
          "elegir": {
            "type": "boolean",
            "default": false,
            "description": "true: marca como elegida la opción con el precio del BC3"
          }
        }
      },
      "PeticionPlano": {
        "type": "object",
        "properties": {
          "fichero": {
            "$ref": "#/components/schemas/Fichero"
          },
          "formato": {
            "type": "string",
            "enum": [
              "magicplan-api",
              "magicplan-csv",
              "ifc",
              "dxf",
              "planner5d",
              "mireforma-plano/1"
            ]
          },
          "plano": {
            "type": "object"
          },
          "magicplan": {
            "type": "object"
          },
          "planner5d": {
            "type": "object"
          },
          "dry_run": {
            "type": "boolean",
            "default": false
          },
          "actualizar": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "PeticionPlanoRemoto": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "proveedor",
              "plan_id",
              "customer_id",
              "api_key"
            ],
            "properties": {
              "proveedor": {
                "const": "magicplan"
              },
              "plan_id": {
                "type": "string"
              },
              "customer_id": {
                "type": "string"
              },
              "api_key": {
                "type": "string",
                "writeOnly": true
              },
              "dry_run": {
                "type": "boolean"
              },
              "actualizar": {
                "type": "boolean"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "proveedor",
              "project_hash",
              "token"
            ],
            "properties": {
              "proveedor": {
                "const": "planner5d"
              },
              "project_hash": {
                "type": "string"
              },
              "token": {
                "type": "string",
                "writeOnly": true
              },
              "dry_run": {
                "type": "boolean"
              },
              "actualizar": {
                "type": "boolean"
              }
            }
          }
        ]
      },
      "ResultadoImportacion": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "dry_run": {
            "type": "boolean"
          },
          "origen": {
            "type": "object"
          },
          "resumen": {
            "type": "object"
          },
          "detalle": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      }
    }
  }
}