"""Lead summary writing for Alba Core.
This module turns verified extraction and matching results into a plain staff
handoff. It should not perform matching itself, call PropertyMe, or invent
marketing claims.
"""
from __future__ import annotations
from app.alba_core.models import MatchResult, RentalRequirements
[docs]
def build_lead_summary(requirements: RentalRequirements, matches: list[MatchResult]) -> str:
"""Create a plain staff handoff summary from verified Alba Core output.
The summary is deliberately practical: confirmed requirements first, then
real suggested properties with PropertyMe references.
"""
lines = ["Alba rental lead summary", ""]
lines.append("Customer requirements")
lines.append(f"- Location: {requirements.city or 'Not confirmed'}")
lines.append(f"- Budget: {money(requirements.budget_max) if requirements.budget_max else 'Not confirmed'}")
lines.append(f"- Bedrooms: {requirements.bedrooms_min}+")
if requirements.bathrooms_min is not None:
lines.append(f"- Bathrooms: {requirements.bathrooms_min}+")
if requirements.property_type:
lines.append(f"- Property type: {requirements.property_type}")
if requirements.move_in_timing:
lines.append(f"- Move-in timing: {requirements.move_in_timing}")
if requirements.priority:
lines.append(f"- Priority: {requirements.priority}")
if requirements.features:
lines.append(f"- Lifestyle extras: {', '.join(requirements.features)}")
lines.append("")
if not matches:
lines.append("No matching real listings were found in the current PropertyMe cache.")
lines.append("Recommended action: confirm whether the customer can adjust location, budget, or bedrooms.")
return "\n".join(lines)
lines.append("Suggested properties")
for index, match in enumerate(matches, 1):
property_record = match.property
lines.append(
f"{index}. {property_record.address} - {money(property_record.rent_pw)} pw, "
f"{property_record.bedrooms or 'unknown'} bed, {property_record.bathrooms or 'unknown'} bath"
)
lines.append(f" Reason: {' '.join(match.match_notes[:3])}")
lines.append(f" PropertyMe ref: {property_record.property_id}")
return "\n".join(lines)
[docs]
def money(value: float | None) -> str:
"""Format a weekly rent value for summaries."""
if value is None:
return "Unknown"
return f"${value:,.0f} NZD"