{
  "openapi": "3.1.0",
  "info": {
    "title": "Homly Agency API",
    "version": "1.0.0",
    "description": "API pública de Homly para construir sitios web de agencias y agentes inmobiliarios. Devuelve únicamente los inmuebles **publicados** de la agencia dueña de la key. Guía para LLMs: https://api.homly.world/llms.txt",
    "contact": {
      "name": "Homly para Desarrolladores",
      "url": "https://homly.world"
    }
  },
  "servers": [
    {
      "url": "https://api.homly.world/api/v1/agency"
    }
  ],
  "security": [
    {
      "publishableKey": []
    }
  ],
  "tags": [
    {
      "name": "Agency"
    },
    {
      "name": "Properties"
    },
    {
      "name": "Agents"
    },
    {
      "name": "Leads"
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "operationId": "getAgency",
        "summary": "Datos de la agencia de la key",
        "tags": [
          "Agency"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Me"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/properties": {
      "get": {
        "operationId": "listProperties",
        "summary": "Listar inmuebles publicados",
        "description": "Solo inmuebles de la agencia dueña de la key, en estado `available` o `reserved`. Los filtros usan la sintaxis `filter[campo]=valor`.",
        "tags": [
          "Properties"
        ],
        "parameters": [
          {
            "name": "filter[city]",
            "in": "query",
            "description": "Ciudad (coincidencia parcial).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "filter[neighborhood]",
            "in": "query",
            "description": "Urbanización/zona (coincidencia parcial).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "filter[property_type]",
            "in": "query",
            "description": "Tipo exacto.",
            "schema": {
              "type": "string",
              "enum": [
                "apartment",
                "house",
                "villa",
                "studio",
                "penthouse",
                "duplex",
                "loft",
                "townhouse",
                "office",
                "commercial",
                "warehouse",
                "land",
                "parking",
                "storage"
              ]
            }
          },
          {
            "name": "filter[operation_type]",
            "in": "query",
            "description": "Operación exacta.",
            "schema": {
              "type": "string",
              "enum": [
                "sale",
                "rent",
                "both",
                "transfer"
              ]
            }
          },
          {
            "name": "filter[bedrooms]",
            "in": "query",
            "description": "Habitaciones (exacto).",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "filter[bathrooms]",
            "in": "query",
            "description": "Baños (exacto).",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "filter[min_price]",
            "in": "query",
            "description": "Precio mínimo (venta o alquiler).",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "filter[max_price]",
            "in": "query",
            "description": "Precio máximo (venta o alquiler).",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "description": "Orden. Prefijo `-` = descendente. Defecto `-created_at`.",
            "schema": {
              "type": "string",
              "enum": [
                "created_at",
                "-created_at",
                "price_sale",
                "-price_sale",
                "price_rent",
                "-price_rent"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PropertyPage"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/properties/by-slug/{slug}": {
      "get": {
        "operationId": "getPropertyBySlug",
        "summary": "Inmueble por slug",
        "tags": [
          "Properties"
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Property"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/properties/{id}": {
      "get": {
        "operationId": "getProperty",
        "summary": "Inmueble por id",
        "tags": [
          "Properties"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Property"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/search": {
      "get": {
        "operationId": "searchProperties",
        "summary": "Búsqueda de texto libre",
        "tags": [
          "Properties"
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Texto a buscar (obligatorio).",
            "schema": {
              "type": "string",
              "minLength": 1
            },
            "required": true
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PropertyPage"
                }
              }
            }
          },
          "400": {
            "description": "Falta `q`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/agents": {
      "get": {
        "operationId": "listAgents",
        "summary": "Listar agentes activos",
        "tags": [
          "Agents"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentPage"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/agents/{id}": {
      "get": {
        "operationId": "getAgent",
        "summary": "Agente por id",
        "tags": [
          "Agents"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Agent"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/leads": {
      "post": {
        "operationId": "createLead",
        "summary": "Crear un lead (formulario de contacto)",
        "description": "**Requiere key secreta (`sk_live_`)**: no se puede llamar desde el navegador. Hazlo desde un backend/función serverless/proxy. Soporta `Idempotency-Key` (24 h).",
        "tags": [
          "Leads"
        ],
        "security": [
          {
            "secretKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string"
            },
            "description": "Reintentos seguros: misma key = misma respuesta (200 en vez de 201)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LeadInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Lead"
                }
              }
            }
          },
          "200": {
            "description": "Repetido por Idempotency-Key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Lead"
                }
              }
            }
          },
          "422": {
            "description": "Validación",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "errors": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "publishableKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "pk_live_…",
        "description": "Key publicable (`pk_live_`, 40 caracteres). Solo lectura. Segura en el navegador **solo** desde el dominio verificado de la agencia (CORS)."
      },
      "secretKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "sk_live_…",
        "description": "Key secreta (`sk_live_`). Nunca en el frontend. Necesaria para crear leads. Límite 60/min."
      }
    },
    "parameters": {
      "Page": {
        "name": "page",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "default": 1
        }
      },
      "PerPage": {
        "name": "per_page",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 50,
          "default": 20
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Key ausente, mal formada, inválida o revocada.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Agencia inactiva, suscripción vencida/cancelada, o tipo de key incorrecto.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "No existe o no pertenece a la agencia.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Demasiadas solicitudes. Respeta `Retry-After`.",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "integer"
            }
          }
        }
      }
    },
    "schemas": {
      "Property": {
        "type": "object",
        "description": "Inmueble publicado (estados `available` o `reserved`).",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "slug": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "reference_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "city": {
            "type": [
              "string",
              "null"
            ]
          },
          "neighborhood": {
            "type": [
              "string",
              "null"
            ]
          },
          "property_type": {
            "type": "string",
            "enum": [
              "apartment",
              "house",
              "villa",
              "studio",
              "penthouse",
              "duplex",
              "loft",
              "townhouse",
              "office",
              "commercial",
              "warehouse",
              "land",
              "parking",
              "storage"
            ]
          },
          "operation_type": {
            "type": "string",
            "enum": [
              "sale",
              "rent",
              "both",
              "transfer"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "available",
              "reserved"
            ]
          },
          "price_sale": {
            "type": [
              "number",
              "null"
            ],
            "description": "Precio de venta; null si no se vende."
          },
          "price_rent": {
            "type": [
              "number",
              "null"
            ],
            "description": "Precio de alquiler; null si no se alquila."
          },
          "currency": {
            "type": [
              "string",
              "null"
            ],
            "examples": [
              "USD"
            ]
          },
          "bedrooms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "bathrooms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "built_area_m2": {
            "type": [
              "number",
              "null"
            ]
          },
          "allows_pets": {
            "type": "boolean"
          },
          "is_featured": {
            "type": "boolean"
          },
          "agent_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "public_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Ficha pública en myhomly.com o en el dominio propio verificado de la agencia."
          },
          "location": {
            "type": "object",
            "description": "Sin dirección exacta ni código postal. Coordenadas redondeadas (~110 m).",
            "properties": {
              "state": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "country": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "neighborhood": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "city": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "coordinates": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "lat": {
                    "type": "number"
                  },
                  "lng": {
                    "type": "number"
                  }
                }
              }
            }
          },
          "details": {
            "type": "object",
            "properties": {
              "total_area_m2": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "built_area_m2": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "bedrooms": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "bathrooms": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "half_bathrooms": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "parking_spaces": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "floor_number": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "total_floors": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "year_built": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          },
          "amenities": {
            "type": "object",
            "properties": {
              "is_furnished": {
                "type": [
                  "boolean",
                  "null"
                ]
              },
              "furniture_included": {
                "type": [
                  "boolean",
                  "null"
                ]
              },
              "allows_pets": {
                "type": [
                  "boolean",
                  "null"
                ]
              },
              "pet_restrictions": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "features": {
                "description": "Lista de características (texto libre).",
                "type": [
                  "array",
                  "object",
                  "null"
                ]
              },
              "nearby_services": {
                "type": [
                  "array",
                  "object",
                  "null"
                ]
              },
              "power_plant": {
                "type": "boolean"
              },
              "water_well": {
                "type": "boolean"
              },
              "direct_gas": {
                "type": "boolean"
              }
            }
          },
          "media": {
            "type": "object",
            "properties": {
              "primary_image_url": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uri"
              },
              "images": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "uri"
                    },
                    "thumbnail_url": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "uri"
                    },
                    "alt_text": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "is_primary": {
                      "type": "boolean"
                    },
                    "order": {
                      "type": "integer"
                    }
                  }
                },
                "description": "Ordenadas por `order`."
              },
              "virtual_tour_url": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "video_url": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "agent": {
            "type": [
              "object",
              "null"
            ],
            "description": "Solo si la propiedad tiene agente asignado. El email nunca se expone.",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "photo_url": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uri"
              },
              "phone": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Solo si el agente lo publica."
              }
            }
          },
          "offers_financing": {
            "type": "boolean"
          },
          "published_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Agent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "photo_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "bio": {
            "type": [
              "string",
              "null"
            ]
          },
          "agency_id": {
            "type": "string",
            "format": "uuid"
          },
          "slug": {
            "type": [
              "string",
              "null"
            ]
          },
          "phone": {
            "type": [
              "string",
              "null"
            ],
            "description": "Solo si el agente lo publica."
          }
        }
      },
      "Me": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "contact_email": {
            "type": [
              "string",
              "null"
            ]
          },
          "custom_domain": {
            "type": [
              "string",
              "null"
            ],
            "description": "Dominio propio verificado, sin https://."
          },
          "api_version": {
            "type": "string",
            "examples": [
              "v1"
            ]
          }
        }
      },
      "LeadInput": {
        "type": "object",
        "required": [
          "name",
          "email"
        ],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 120
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 160
          },
          "phone": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 32
          },
          "message": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 2000
          },
          "property_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Debe ser un inmueble de la agencia."
          }
        }
      },
      "Lead": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string"
              },
              "email": {
                "type": "string"
              },
              "status": {
                "type": "string",
                "examples": [
                  "new"
                ]
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "description": "invalid_key, scope_invalid, agency_inactive, subscription_blocked, rate_limited, not_found, validation_error"
              },
              "message": {
                "type": "string"
              },
              "doc_url": {
                "type": "string"
              }
            }
          }
        }
      },
      "PageMeta": {
        "type": "object",
        "properties": {
          "current_page": {
            "type": "integer"
          },
          "last_page": {
            "type": "integer"
          },
          "per_page": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          },
          "from": {
            "type": [
              "integer",
              "null"
            ]
          },
          "to": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "Links": {
        "type": "object",
        "properties": {
          "first": {
            "type": [
              "string",
              "null"
            ]
          },
          "last": {
            "type": [
              "string",
              "null"
            ]
          },
          "prev": {
            "type": [
              "string",
              "null"
            ]
          },
          "next": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "PropertyPage": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Property"
            }
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          },
          "meta": {
            "$ref": "#/components/schemas/PageMeta"
          }
        }
      },
      "AgentPage": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Agent"
            }
          },
          "links": {
            "$ref": "#/components/schemas/Links"
          },
          "meta": {
            "$ref": "#/components/schemas/PageMeta"
          }
        }
      }
    }
  }
}