{
  "openapi": "3.1.0",
  "info": {
    "title": "WyldSafe Agent API",
    "version": "1.0.0",
    "summary": "Address-only wildfire screening for homeowner-assist agents.",
    "description": "WyldSafe screens a property from a satellite image plus the homeowner's own\nanswers. An agent may run the free Tier 1 screening on a homeowner's behalf\nwithout any credentials; the homeowner keeps the consent decision.\n\nAgent rules of the road:\n1. Attach the canonical disclaimer (below) to anything you show the homeowner.\n2. Never accept Terms or Privacy on the homeowner's behalf. Hand them the\n   wyldsafe.com URL and let them complete create-account / claim / verify-otp\n   on their own device. The consent artifact is stored in `consent_records`.\n3. Do not submit homeowner contact details in screening requests. Identity\n   and sharing endpoints are not part of delegated screening.\n4. Tier 1 costs satellite and geocoding money. It is rate limited per client\n   (IP + user-agent hash) at 100 creates per one-hour window, then a 10-minute\n   lockout. Do not retry a 429 on a timer; ask the homeowner instead.\n\nCanonical disclaimer (v2026-11-20): WyldSafe is a screening tool, not a fire-safety certification, not a designated Wildfire Mitigation Provider under California SB 894, and not a warranty that a structure will survive a wildfire. Insurance discounts are determined by the carrier, not by WyldSafe. Completed-work entries are homeowner-reported and unverified by WyldSafe.",
    "contact": {
      "name": "WyldSafe Developer Docs",
      "url": "https://wyldsafe.com/developers"
    },
    "termsOfService": "https://wyldsafe.com/terms",
    "x-disclaimer": {
      "version": "2026-11-20",
      "text": "WyldSafe is a screening tool, not a fire-safety certification, not a designated Wildfire Mitigation Provider under California SB 894, and not a warranty that a structure will survive a wildfire. Insurance discounts are determined by the carrier, not by WyldSafe. Completed-work entries are homeowner-reported and unverified by WyldSafe.",
      "not_a_certification": true,
      "not_sb_894_designated": true,
      "survival_warranty": false,
      "discounts_determined_by": "carrier",
      "completed_work_verification": "homeowner_reported_unverified",
      "consent": {
        "model": "homeowner_accepts_in_person",
        "agent_may_accept_terms": false,
        "homeowner_flows": [
          "POST /api/v1/assessments/{assessmentId}/create-account",
          "POST /api/v1/assessments/{assessmentId}/claim",
          "POST /api/v1/assessments/{assessmentId}/verify-otp"
        ],
        "artifact_table": "consent_records"
      },
      "agent_data_policy": "screening_responses_return_status_and_findings_only",
      "homeowner_only_paths": [
        {
          "method": "POST",
          "path": "/api/v1/assessments/{assessmentId}/create-account",
          "reason": "Returns the homeowner's own email and creates their account."
        },
        {
          "method": "POST",
          "path": "/api/v1/assessments/{assessmentId}/verify-otp",
          "reason": "Returns the homeowner's session bearer token."
        },
        {
          "method": "POST",
          "path": "/api/v1/assessments/{assessmentId}/claim",
          "reason": "Moves ownership to the signed-in homeowner."
        }
      ],
      "references": {
        "developer_docs": "https://wyldsafe.com/developers",
        "openapi": "https://api.wyldsafe.com/api/openapi.json",
        "llms_txt": "https://wyldsafe.com/llms.txt",
        "terms": "https://wyldsafe.com/terms",
        "privacy": "https://wyldsafe.com/privacy"
      }
    },
    "x-rate-limits": {
      "POST /api/v1/assessments/tier1": "100 per hour per client (IP + user-agent hash), 10 minute lockout on breach"
    }
  },
  "externalDocs": {
    "description": "Human-readable developer guide (also read /llms.txt and /llms-full.txt)",
    "url": "https://wyldsafe.com/developers"
  },
  "servers": [
    {
      "url": "https://api.wyldsafe.com",
      "description": "Production (wrangler env=production)"
    },
    {
      "url": "https://dev.api.wyldsafe.com",
      "description": "Development (wrangler default env)"
    }
  ],
  "tags": [
    {
      "name": "Screening",
      "description": "Free, unauthenticated address-only Tier 1 screening."
    },
    {
      "name": "Homeowner",
      "description": "Homeowner-authenticated steps an agent must not perform for the homeowner."
    },
    {
      "name": "Sharing",
      "description": "Share-invitation validation and acceptance."
    },
    {
      "name": "Meta",
      "description": "Health and discovery."
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "Meta"
        ],
        "summary": "Service health",
        "description": "Handled in src/index.ts before any auth or routing.",
        "responses": {
          "200": {
            "description": "Service is healthy.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "service",
                    "timestamp"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "examples": [
                        "healthy"
                      ]
                    },
                    "service": {
                      "type": "string",
                      "examples": [
                        "wyldsafe-api"
                      ]
                    },
                    "timestamp": {
                      "type": "integer",
                      "format": "int64",
                      "description": "ms epoch."
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/assessments/tier1": {
      "post": {
        "tags": [
          "Screening"
        ],
        "summary": "Create a Tier 1 satellite screening from an address",
        "description": "No authentication required. Geocodes the address, fetches a satellite image and returns a zone-by-zone screening result plus the assessmentId needed for every later step. Rate limited: 100 per hour per client, then a 10-minute lockout.",
        "operationId": "createTier1",
        "x-rate-limited": true,
        "x-consent-required-before-next-step": true,
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "address"
                ],
                "properties": {
                  "address": {
                    "type": "string",
                    "description": "Freeform street address, e.g. '123 Main St, Crestline, CA 92325'."
                  },
                  "preferredLanguage": {
                    "type": "string",
                    "description": "BCP-47-ish code; non-en triggers a translated summary."
                  },
                  "latitude": {
                    "type": "number"
                  },
                  "longitude": {
                    "type": "number"
                  },
                  "funnelSource": {
                    "type": "string"
                  },
                  "utmSource": {
                    "type": "string"
                  },
                  "utmMedium": {
                    "type": "string"
                  },
                  "utmCampaign": {
                    "type": "string"
                  },
                  "utmTerm": {
                    "type": "string"
                  },
                  "utmContent": {
                    "type": "string"
                  },
                  "refCode": {
                    "type": "string",
                    "description": "Broker/partner referral code."
                  },
                  "visitorId": {
                    "type": "string",
                    "maxLength": 64,
                    "description": "Site visitor id (wyldsafe_vid)."
                  },
                  "experiments": {
                    "type": "object",
                    "description": "A/B map {experimentId: variantKey}, max 10 entries."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Screening created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "assessmentId",
                        "currentTier",
                        "disclaimer"
                      ],
                      "properties": {
                        "assessmentId": {
                          "type": "string"
                        },
                        "satelliteUrl": {
                          "type": "string",
                          "format": "uri"
                        },
                        "currentTier": {
                          "type": "integer",
                          "const": 1
                        },
                        "analysis": {
                          "$ref": "#/components/schemas/Tier1Analysis"
                        },
                        "address": {
                          "$ref": "#/components/schemas/AddressMetadata"
                        },
                        "calFireZone": {
                          "type": "object",
                          "description": "CAL FIRE Fire Hazard Severity Zone, present only when the lookup succeeded.",
                          "properties": {
                            "hazardClass": {
                              "type": "string",
                              "examples": [
                                "Very High",
                                "Extreme"
                              ]
                            },
                            "hazardCode": {
                              "type": "string"
                            },
                            "jurisdiction": {
                              "type": "string"
                            },
                            "jurisdictionFull": {
                              "type": "string"
                            },
                            "description": {
                              "type": "string"
                            },
                            "source": {
                              "type": "string"
                            }
                          }
                        },
                        "disclaimer": {
                          "$ref": "#/components/schemas/AgentDisclaimer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "description": "Rate limit breached (100/hour per client). 10-minute lockout; do not retry sooner.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "description": "Failure envelope produced by src/lib/errors.ts createErrorResponse().",
                  "required": [
                    "success",
                    "error"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": false
                    },
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message"
                      ],
                      "properties": {
                        "code": {
                          "type": "string",
                          "description": "Stable machine code, e.g. RATE_LIMITED, NOT_FOUND, UNAUTHORIZED."
                        },
                        "message": {
                          "type": "string"
                        },
                        "details": {}
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/assessments/{assessmentId}/tier1": {
      "get": {
        "tags": [
          "Screening"
        ],
        "summary": "Read a Tier 1 screening result",
        "description": "Readable without auth while the assessment is unowned and in draft/active, so the anonymous funnel can poll results. Once a homeowner is attached, their session is required and a non-owner gets 403.",
        "operationId": "getTier1",
        "parameters": [
          {
            "name": "assessmentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "preferredLanguage",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Non-en values refresh the translated summary."
          }
        ],
        "responses": {
          "200": {
            "description": "Tier 1 result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "assessmentId",
                        "currentTier",
                        "disclaimer"
                      ],
                      "properties": {
                        "assessmentId": {
                          "type": "string"
                        },
                        "visitReason": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Homeowner's stated reason for the assessment (assessment_journeys), null when not captured.",
                          "properties": {
                            "status": {
                              "type": "string"
                            },
                            "code": {
                              "type": "string"
                            },
                            "detail": {
                              "type": "string"
                            }
                          }
                        },
                        "satelliteUrl": {
                          "type": "string",
                          "format": "uri"
                        },
                        "analysis": {
                          "$ref": "#/components/schemas/Tier1Analysis"
                        },
                        "riskScore": {
                          "type": "number"
                        },
                        "riskCategory": {
                          "type": "string",
                          "enum": [
                            "low",
                            "medium",
                            "high",
                            "extreme"
                          ]
                        },
                        "currentTier": {
                          "type": "integer"
                        },
                        "address": {
                          "type": "string"
                        },
                        "disclaimer": {
                          "$ref": "#/components/schemas/AgentDisclaimer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/assessments/{assessmentId}/tier2": {
      "post": {
        "tags": [
          "Homeowner"
        ],
        "summary": "Submit the homeowner's Tier 2 answers",
        "description": "Owner-authenticated (Bearer session token). Tier 1 must be complete. Answers are the homeowner's own statements about their property, so an agent may transcribe them but must not invent them and must not hold the homeowner's session.",
        "operationId": "submitTier2",
        "security": [
          {
            "sessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "assessmentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "roofMaterial": {
                    "type": "string"
                  },
                  "roofAge": {
                    "type": "string"
                  },
                  "ventType": {
                    "type": "string"
                  },
                  "yearBuilt": {
                    "type": "integer"
                  },
                  "sidingMaterial": {
                    "type": "string"
                  },
                  "deckPresent": {
                    "type": "boolean"
                  },
                  "deckMaterial": {
                    "type": "string"
                  },
                  "defensibleSpaceZone0": {
                    "type": "boolean"
                  },
                  "defensibleSpaceZone1": {
                    "type": "boolean"
                  },
                  "treesOverhangingRoof": {
                    "type": "boolean"
                  },
                  "vegetationAgainstHouse": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Tier 2 stored.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "assessmentId",
                        "currentTier",
                        "disclaimer"
                      ],
                      "properties": {
                        "assessmentId": {
                          "type": "string"
                        },
                        "currentTier": {
                          "type": "integer",
                          "const": 2
                        },
                        "tier2Data": {
                          "type": "object"
                        },
                        "disclaimer": {
                          "$ref": "#/components/schemas/AgentDisclaimer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "get": {
        "tags": [
          "Homeowner"
        ],
        "summary": "Read stored Tier 2 answers",
        "description": "Owner-authenticated (Bearer session token).",
        "operationId": "getTier2",
        "security": [
          {
            "sessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "assessmentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tier 2 data.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "assessmentId",
                        "currentTier",
                        "disclaimer"
                      ],
                      "properties": {
                        "assessmentId": {
                          "type": "string"
                        },
                        "tier2Data": {
                          "type": [
                            "object",
                            "null"
                          ]
                        },
                        "tier2CompletedAt": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "format": "int64"
                        },
                        "currentTier": {
                          "type": "integer"
                        },
                        "disclaimer": {
                          "$ref": "#/components/schemas/AgentDisclaimer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/assessments/{assessmentId}/create-account": {
      "post": {
        "tags": [
          "Homeowner"
        ],
        "summary": "Homeowner creates their account and accepts Terms + Privacy",
        "description": "MUST be performed by the homeowner, not the agent. `termsAccepted` and `privacyAccepted` are validated as literal true, and the affirmative click is persisted to `consent_records` (one row per document) with ip + user-agent. An agent may hand over the wyldsafe.com URL; it may not click for the homeowner.",
        "operationId": "createAccount",
        "x-agent-must-not-perform": true,
        "parameters": [
          {
            "name": "assessmentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "termsAccepted",
                  "privacyAccepted"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "termsAccepted": {
                    "type": "boolean",
                    "const": true
                  },
                  "privacyAccepted": {
                    "type": "boolean",
                    "const": true
                  },
                  "softConsent": {
                    "$ref": "#/components/schemas/SoftConsent"
                  },
                  "referrerConsent": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Account created. The body echoes the homeowner's own email, so this is a homeowner-only call and carries no disclaimer block (see disclaimer.homeowner_only_paths on the screening payloads).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "oneOf": [
                        {
                          "type": "object",
                          "description": "New account created and OTP sent.",
                          "required": [
                            "assessmentId",
                            "userId",
                            "email",
                            "needsOtpVerification",
                            "emailSent"
                          ],
                          "properties": {
                            "assessmentId": {
                              "type": "string"
                            },
                            "userId": {
                              "type": "string"
                            },
                            "email": {
                              "type": "string",
                              "format": "email"
                            },
                            "needsOtpVerification": {
                              "type": "boolean",
                              "const": true
                            },
                            "emailSent": {
                              "type": "boolean",
                              "description": "False when SendGrid failed; the homeowner can resend."
                            }
                          }
                        },
                        {
                          "type": "object",
                          "description": "Idempotent repeat with the same email.",
                          "required": [
                            "assessmentId",
                            "userId",
                            "email",
                            "currentTier"
                          ],
                          "properties": {
                            "assessmentId": {
                              "type": "string"
                            },
                            "userId": {
                              "type": "string"
                            },
                            "email": {
                              "type": "string",
                              "format": "email"
                            },
                            "currentTier": {
                              "type": "integer"
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/assessments/{assessmentId}/claim": {
      "post": {
        "tags": [
          "Homeowner"
        ],
        "summary": "Attach a signed-in homeowner to an agent-started assessment",
        "description": "Requires the homeowner's session. Attaches an unowned assessment or one already theirs, attempts to ensure a property record, and writes `consent_records` (source='claim'). Missing or invalid softConsent falls back to legacy rows and does not prove a versioned click.",
        "operationId": "claimAssessment",
        "x-agent-must-not-perform": true,
        "security": [
          {
            "sessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "assessmentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "softConsent": {
                    "$ref": "#/components/schemas/SoftConsent"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "assessmentId",
                        "userId",
                        "propertyId",
                        "consentRecorded",
                        "disclaimer"
                      ],
                      "properties": {
                        "assessmentId": {
                          "type": "string"
                        },
                        "userId": {
                          "type": "string"
                        },
                        "propertyId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "consentRecorded": {
                          "type": "boolean",
                          "description": "True if at least one row was written, not proof both documents were recorded."
                        },
                        "disclaimer": {
                          "$ref": "#/components/schemas/AgentDisclaimer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/assessments/{assessmentId}/resend-otp": {
      "post": {
        "tags": [
          "Homeowner"
        ],
        "summary": "Re-send the verification OTP to the homeowner",
        "description": "The OTP goes to the homeowner's own contact channel and must be entered by them. An agent that receives an OTP code is out of policy.",
        "operationId": "resendAssessmentOtp",
        "x-agent-must-not-perform": true,
        "parameters": [
          {
            "name": "assessmentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Code regenerated; check emailSent for delivery status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "assessmentId",
                        "emailSent",
                        "emailError"
                      ],
                      "properties": {
                        "assessmentId": {
                          "type": "string"
                        },
                        "emailSent": {
                          "type": "boolean"
                        },
                        "emailError": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/assessments/{assessmentId}/verify-otp": {
      "post": {
        "tags": [
          "Homeowner"
        ],
        "summary": "Homeowner enters their 6-digit OTP",
        "description": "Verifies the code against the stored OTP, activates the assessment and returns the homeowner's session token. An agent must never hold this token.",
        "operationId": "verifyOtp",
        "x-agent-must-not-perform": true,
        "parameters": [
          {
            "name": "assessmentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "otp"
                ],
                "properties": {
                  "otp": {
                    "type": "string",
                    "minLength": 6,
                    "maxLength": 6
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verified. Session token belongs to the homeowner. This response has no disclaimer block.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "assessmentId",
                        "token",
                        "user"
                      ],
                      "properties": {
                        "assessmentId": {
                          "type": "string"
                        },
                        "token": {
                          "type": "string",
                          "description": "Homeowner session bearer token. Never store or proxy this as an agent."
                        },
                        "user": {
                          "type": "object",
                          "required": [
                            "isAdmin"
                          ],
                          "properties": {
                            "id": {
                              "type": "string"
                            },
                            "email": {
                              "type": "string",
                              "format": "email"
                            },
                            "isAdmin": {
                              "type": "boolean",
                              "const": false
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/shares/validate/{token}": {
      "get": {
        "tags": [
          "Sharing"
        ],
        "summary": "Validate a share invitation (public preview)",
        "description": "Public with an invitation token. Records a click and returns a recipient preview containing contact information. Not for screening agents.",
        "operationId": "validateShare",
        "x-agent-must-not-perform": true,
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Share preview.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "shareId",
                        "status",
                        "recipientEmail",
                        "senderName",
                        "propertyAddress",
                        "riskCategory",
                        "expiresAt",
                        "requiresAuth"
                      ],
                      "properties": {
                        "shareId": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "pending",
                            "clicked",
                            "accepted",
                            "expired"
                          ],
                          "description": "Status read before click tracking updates it."
                        },
                        "recipientEmail": {
                          "type": "string",
                          "format": "email"
                        },
                        "senderName": {
                          "type": "string"
                        },
                        "propertyAddress": {
                          "type": "string"
                        },
                        "riskCategory": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "expiresAt": {
                          "type": "integer",
                          "format": "int64"
                        },
                        "requiresAuth": {
                          "type": "boolean",
                          "description": "False when the invite is already accepted; not an access grant."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/shares/{token}/accept": {
      "post": {
        "tags": [
          "Sharing"
        ],
        "summary": "Invited recipient accepts a share invitation",
        "description": "Recipient-authenticated, and the signed-in account's email must match the invited recipient email — the token alone never grants access. Acceptance stores `acceptance_terms_version` and writes an 'accepted' share event with the client ip + user-agent, the pattern the delegated-consent design generalizes.",
        "operationId": "acceptShare",
        "x-agent-must-not-perform": true,
        "security": [
          {
            "sessionAuth": []
          }
        ],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "termsVersion"
                ],
                "properties": {
                  "termsVersion": {
                    "type": "string",
                    "description": "Send the terms version shown to the recipient; a valid body omitting it can fail persistence."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "shareId",
                        "assessmentId",
                        "status"
                      ],
                      "properties": {
                        "shareId": {
                          "type": "string"
                        },
                        "assessmentId": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string",
                          "const": "accepted"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "500": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "sessionAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Homeowner session token from lib/auth createUserSession(). Agents must not obtain, store, or reuse it; hand the homeowner the wyldsafe.com URL instead."
      }
    },
    "responses": {
      "Error": {
        "description": "Error envelope (src/lib/errors.ts).",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "description": "Failure envelope produced by src/lib/errors.ts createErrorResponse().",
              "required": [
                "success",
                "error"
              ],
              "properties": {
                "success": {
                  "type": "boolean",
                  "const": false
                },
                "error": {
                  "type": "object",
                  "required": [
                    "code",
                    "message"
                  ],
                  "properties": {
                    "code": {
                      "type": "string",
                      "description": "Stable machine code, e.g. RATE_LIMITED, NOT_FOUND, UNAUTHORIZED."
                    },
                    "message": {
                      "type": "string"
                    },
                    "details": {}
                  }
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "AgentDisclaimer": {
        "title": "AgentDisclaimer",
        "description": "Canonical legal/safety block. Required in every screening payload. Reproduce `text` verbatim when presenting WyldSafe output. Source: src/lib/agent-disclaimer.ts.",
        "type": "object",
        "required": [
          "version",
          "text",
          "not_a_certification",
          "not_sb_894_designated",
          "survival_warranty",
          "discounts_determined_by",
          "completed_work_verification",
          "consent",
          "agent_data_policy",
          "references"
        ],
        "properties": {
          "version": {
            "type": "string",
            "examples": [
              "2026-11-20"
            ]
          },
          "text": {
            "type": "string",
            "examples": [
              "WyldSafe is a screening tool, not a fire-safety certification, not a designated Wildfire Mitigation Provider under California SB 894, and not a warranty that a structure will survive a wildfire. Insurance discounts are determined by the carrier, not by WyldSafe. Completed-work entries are homeowner-reported and unverified by WyldSafe."
            ]
          },
          "not_a_certification": {
            "type": "boolean",
            "const": true
          },
          "not_sb_894_designated": {
            "type": "boolean",
            "const": true
          },
          "survival_warranty": {
            "type": "boolean",
            "const": false
          },
          "discounts_determined_by": {
            "type": "string",
            "const": "carrier"
          },
          "completed_work_verification": {
            "type": "string",
            "const": "homeowner_reported_unverified"
          },
          "agent_data_policy": {
            "type": "string",
            "const": "screening_responses_return_status_and_findings_only"
          },
          "consent": {
            "type": "object"
          },
          "references": {
            "type": "object"
          }
        }
      },
      "Tier1Analysis": {
        "title": "Tier1Analysis",
        "description": "Satellite-image screening result (src/lib/claude.ts Tier1AnalysisResult).",
        "type": "object",
        "required": [
          "zones",
          "overallScore",
          "riskCategory",
          "summary",
          "propertyEstimates"
        ],
        "properties": {
          "zones": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Per-zone scores (ZoneScore[])."
          },
          "overallScore": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "riskCategory": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high",
              "extreme"
            ]
          },
          "summary": {
            "type": "string",
            "description": "English expert summary."
          },
          "summaryEnglish": {
            "type": "string"
          },
          "summaryTranslated": {
            "type": "string"
          },
          "summaryLanguage": {
            "type": "string"
          },
          "propertyEstimates": {
            "type": "object",
            "description": "Size estimates using cars as scale."
          }
        }
      },
      "AddressMetadata": {
        "title": "AddressMetadata",
        "type": "object",
        "required": [
          "formattedAddress"
        ],
        "properties": {
          "formattedAddress": {
            "type": "string"
          },
          "street": {
            "type": "string"
          },
          "city": {
            "type": "string"
          },
          "state": {
            "type": "string"
          },
          "zipCode": {
            "type": "string"
          },
          "county": {
            "type": "string"
          },
          "latitude": {
            "type": "number"
          },
          "longitude": {
            "type": "number"
          }
        }
      },
      "SoftConsent": {
        "title": "SoftConsent",
        "description": "The homeowner's affirmative click, forwarded from the site (src/utils/softConsent.ts, SOFT_CONSENT_VERSION). The API records the per-document versions in consent_records; the top-level version is validated for shape, not persisted or enforced as current.",
        "type": "object",
        "required": [
          "version",
          "acceptedAt",
          "surface",
          "documents"
        ],
        "properties": {
          "version": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64,
            "examples": [
              "2026-10-05"
            ]
          },
          "acceptedAt": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "Client-reported ms epoch of the affirmative click."
          },
          "surface": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64,
            "examples": [
              "tier1_cta",
              "cinematic_hook_cta",
              "capture_start",
              "survey_start"
            ]
          },
          "documents": {
            "type": "object",
            "required": [
              "terms",
              "privacy"
            ],
            "properties": {
              "terms": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64
              },
              "privacy": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64
              }
            }
          },
          "locale": {
            "type": "string",
            "maxLength": 32
          },
          "path": {
            "type": "string",
            "maxLength": 512
          }
        }
      }
    }
  }
}