{
  "openapi": "3.1.0",
  "info": {
    "title": "Ibero.center — consulta para alta de trabajadores",
    "version": "1.0.0",
    "description": "Consulta autorizada por RUT, sin requisito de publicación. Requiere person_lookup_enabled adicional; comparte créditos con contactos. Respuestas útiles consumen una consulta por RUT y mes."
  },
  "servers": [
    {
      "url": "https://ibero.center"
    }
  ],
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer"
      },
      "dedicatedKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Ibero-Api-Key"
      }
    },
    "schemas": {
      "Contact": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "email",
          "phone",
          "enrichedAt"
        ],
        "properties": {
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email"
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "enrichedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Quota": {
        "type": "object",
        "required": [
          "planKey",
          "limit",
          "used",
          "pending",
          "remaining",
          "period",
          "resetsAt"
        ],
        "properties": {
          "planKey": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "plus",
              "pro",
              "max",
              null
            ]
          },
          "limit": {
            "type": "integer"
          },
          "used": {
            "type": "integer"
          },
          "pending": {
            "type": "integer"
          },
          "remaining": {
            "type": "integer"
          },
          "period": {
            "type": "string",
            "format": "date"
          },
          "resetsAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Result": {
        "type": "object",
        "required": [
          "person",
          "cached",
          "charged",
          "quota"
        ],
        "properties": {
          "cached": {
            "type": "boolean"
          },
          "charged": {
            "type": "boolean"
          },
          "code": {
            "type": "string"
          },
          "quota": {
            "$ref": "#/components/schemas/Quota"
          },
          "person": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Person"
              },
              {
                "type": "null"
              }
            ]
          },
          "pensionAffiliation": {
            "$ref": "#/components/schemas/PensionAffiliation",
            "description": "Opcional; se omite si el almacenamiento no está habilitado o no responde. Sin consumo adicional."
          },
          "pensionLookupStatus": {
            "type": "string",
            "enum": [
              "success",
              "cached",
              "verification_required",
              "unavailable"
            ],
            "description": "Estado opcional de SP; su fallo no bloquea DT. Se conserva el registro privado previo cuando corresponde."
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "quota": {
            "$ref": "#/components/schemas/Quota"
          }
        }
      },
      "Person": {
        "type": "object",
        "required": [
          "firstName",
          "paternalSurname",
          "maternalSurname",
          "birthDate",
          "nationalityCode",
          "email",
          "phone",
          "enrichedAt",
          "addresses"
        ],
        "properties": {
          "firstName": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200
          },
          "paternalSurname": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200
          },
          "maternalSurname": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200
          },
          "birthDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "nationalityCode": {
            "type": [
              "integer",
              "null"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 254
          },
          "phone": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 30
          },
          "enrichedAt": {
            "type": "string",
            "format": "date-time"
          },
          "addresses": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "object",
              "required": [
                "street",
                "number",
                "unit",
                "communeCode",
                "postalCode"
              ],
              "properties": {
                "street": {
                  "type": "string",
                  "maxLength": 200
                },
                "number": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "maxLength": 30
                },
                "unit": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "maxLength": 100
                },
                "communeCode": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "postalCode": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "maxLength": 20
                }
              }
            }
          }
        }
      },
      "PensionAffiliation": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "status",
          "afpCode",
          "afpName",
          "afcAffiliated",
          "source",
          "checkedAt",
          "recordedAt",
          "requiresConfirmation"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "recorded",
              "not_available"
            ]
          },
          "afpCode": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "capital",
              "cuprum",
              "habitat",
              "modelo",
              "planvital",
              "provida",
              "uno",
              null
            ]
          },
          "afpName": {
            "type": [
              "string",
              "null"
            ]
          },
          "afcAffiliated": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "source": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "user_provided_sp_certificate",
              "sp_online",
              null
            ]
          },
          "checkedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "recordedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "requiresConfirmation": {
            "type": "boolean",
            "const": true
          },
          "queriedAt": {
            "type": "string",
            "format": "date-time"
          },
          "afpAffiliationDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "afcAffiliationDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "afpDataAsOfMonth": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^\\d{4}-(0[1-9]|1[0-2])$"
          },
          "afcDataAsOfMonth": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^\\d{4}-(0[1-9]|1[0-2])$"
          }
        },
        "description": "Afiliación privada por cuenta. Fuente manual aportada por usuario o consulta normal en SP; confirmar antes de usar. not_available no significa no afiliación.",
        "allOf": [
          {
            "if": {
              "properties": {
                "source": {
                  "const": "sp_online"
                }
              }
            },
            "then": {
              "required": [
                "queriedAt",
                "afpAffiliationDate",
                "afpDataAsOfMonth",
                "afcAffiliationDate",
                "afcDataAsOfMonth"
              ],
              "properties": {
                "afcAffiliated": {
                  "enum": [
                    true,
                    null
                  ]
                }
              }
            }
          }
        ]
      }
    }
  },
  "paths": {
    "/api/v1/people/lookup": {
      "post": {
        "operationId": "lookupPerson",
        "security": [
          {
            "apiKey": []
          },
          {
            "dedicatedKey": []
          }
        ],
        "description": "Solo integraciones con permiso adicional. Devuelve datos editables para revisión; no requiere ficha en el directorio. Comparte caché y cuota mensual con contactos.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "rut"
                ],
                "properties": {
                  "rut": {
                    "type": "string",
                    "minLength": 8,
                    "maxLength": 20
                  },
                  "includePensionAffiliation": {
                    "type": "boolean",
                    "default": false,
                    "description": "Solicita consulta SP como complemento de una persona DT útil, con autorización de la persona. Sin cargo DT adicional."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Persona DT y cuota; afiliación privada opcional. La consulta SP exige opt-in y puede requerir verificación sin bloquear DT.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Result"
                }
              }
            }
          },
          "400": {
            "description": "INVALID_INPUT or INVALID_RUT",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "INVALID_API_KEY",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "SERVICE_FORBIDDEN, COMPANY_DISABLED, SUBSCRIPTION_REQUIRED or ENRICHMENT_NOT_INCLUDED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "ENRICHMENT_PENDING or ENRICHMENT_EXPIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds before a retry for temporary failures. Monthly quota errors renew on quota.resetsAt.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "415": {
            "description": "JSON_REQUIRED",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "ENRICHMENT_QUOTA_EXCEEDED, RATE_LIMITED or PROVIDER_BUSY",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds before a retry for temporary failures. Monthly quota errors renew on quota.resetsAt.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "503": {
            "description": "PROVIDER_UNAVAILABLE or ENRICHMENT_UNAVAILABLE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds before a retry for temporary failures. Monthly quota errors renew on quota.resetsAt.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "summary": "Consultar datos para alta de trabajador",
        "parameters": [
          {
            "in": "header",
            "name": "X-Ibero-Include-Pension-Affiliation",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "true"
              ]
            },
            "description": "Opt-in equivalente al campo JSON. Compatible con servidores anteriores que ignoran este header."
          }
        ]
      }
    }
  }
}
