{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/secondappraisal-com/json-schema/secondappraisal-com-referral-detail-schema.json",
  "title": "ReferralDetail",
  "description": "A referral with the provider-facing milestone timeline and the financial panel (offers, settlement, exposure before and after, net savings, ROI). SecondAppraisal works for the borrower in the review and any appraisal. The institution determines any GAP benefit under its own contract.",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/secondappraisal-com-openapi.json#/components/schemas/ReferralDetail",
  "allOf": [
    {
      "$ref": "#/$defs/Referral"
    },
    {
      "type": "object",
      "properties": {
        "consultation_number": {
          "description": "Our consultation number, once the borrower activates.",
          "x-data-class": "institution_confidential",
          "type": [
            "string",
            "null"
          ]
        },
        "days_in_appraisal": {
          "description": "Whole days from the `insurer_notified` milestone, when the insurer was notified that the borrower invoked the appraisal clause, until settlement, or until now if it hasn't settled. Null before that milestone.",
          "x-data-class": "institution_confidential",
          "type": [
            "integer",
            "null"
          ]
        },
        "timeline": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "current_milestone": {
                  "anyOf": [
                    {
                      "type": "string",
                      "enum": [
                        "referral_submitted",
                        "borrower_invited",
                        "disclosure_attested",
                        "outreach_in_progress",
                        "borrower_activated",
                        "valuation_report_received",
                        "insurance_details_received",
                        "photos_received",
                        "market_research",
                        "preliminary_estimate_ready",
                        "appraisal_report_complete",
                        "authorization_received",
                        "insurer_notified",
                        "insurer_acknowledged",
                        "insurer_appraiser_appointed",
                        "appraisals_exchanged",
                        "umpire_engaged",
                        "award_letter_issued",
                        "settlement_finalized",
                        "outcome_recorded"
                      ]
                    },
                    {
                      "type": "null"
                    }
                  ],
                  "x-data-class": "public",
                  "description": "New values may be added: show one you don't recognise as not yet known, and don't fail."
                },
                "terminal": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "enum": [
                            "submitted",
                            "invited",
                            "handoff_pending",
                            "outreach_queued",
                            "contact_attempted",
                            "activated",
                            "in_progress",
                            "settled",
                            "closed",
                            "declined",
                            "unreachable",
                            "expired",
                            "cancelled"
                          ],
                          "x-data-class": "public",
                          "description": "New values may be added: show one you don't recognise as not yet known, and don't fail."
                        },
                        "label": {
                          "type": "string",
                          "x-data-class": "public"
                        },
                        "detail": {
                          "type": "string",
                          "x-data-class": "public"
                        }
                      },
                      "required": [
                        "status",
                        "label",
                        "detail"
                      ]
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "phases": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "key": {
                        "type": "string",
                        "enum": [
                          "referral",
                          "setup",
                          "research",
                          "appraisal",
                          "settlement"
                        ],
                        "x-data-class": "public",
                        "description": "New values may be added: treat one you don't recognise as unknown, and don't fail."
                      },
                      "label": {
                        "type": "string",
                        "x-data-class": "public"
                      },
                      "state": {
                        "type": "string",
                        "enum": [
                          "complete",
                          "current",
                          "upcoming",
                          "skipped"
                        ],
                        "x-data-class": "public",
                        "description": "New values may be added: treat one you don't recognise as unknown, and don't fail."
                      },
                      "milestones": {
                        "type": "array",
                        "items": {
                          "$ref": "#/$defs/TimelineMilestone"
                        }
                      }
                    },
                    "required": [
                      "key",
                      "label",
                      "state",
                      "milestones"
                    ]
                  }
                }
              },
              "required": [
                "current_milestone",
                "terminal",
                "phases"
              ]
            },
            {
              "type": "null"
            }
          ],
          "description": "The provider-facing milestone timeline. Null once reporting is withdrawn (`status: reporting_withdrawn`)."
        },
        "financial": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "initial_offer_cents": {
                  "x-data-class": "borrower_personal",
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "current_best_offer_cents": {
                  "x-data-class": "borrower_personal",
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "appraised_value_cents": {
                  "description": "The signed appraisal award's amount, once the award is signed; null until then.",
                  "x-data-class": "borrower_personal",
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "final_settlement_cents": {
                  "x-data-class": "borrower_personal",
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "loan_payoff_cents": {
                  "x-data-class": "borrower_personal",
                  "x-requires-permission": "referrals.contact:read",
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "deductible_cents": {
                  "description": "Deprecated: we stopped collecting the deductible in version 1.4.0. A referral made before then shows the deductible your institution sent until our retention schedule or an erasure clears it; any other referral shows null.",
                  "x-data-class": "borrower_personal",
                  "deprecated": true,
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "fees_paid_cents": {
                  "description": "The consultation fees on this referral, counting any still waiting to be charged, such as an invoice institution's fee before the month's invoice run. Before it settles, they're the fees to date, as `figures_are_final` false says. Once it settles, they're the fees settlement recorded.",
                  "x-data-class": "institution_confidential",
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "gross_uplift_cents": {
                  "x-data-class": "borrower_personal",
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "exposure_before_cents": {
                  "description": "Estimated exposure before the review: the loan payoff minus the insurer's first offer, never below zero. Your institution determines its GAP benefit under its own contract.",
                  "x-data-class": "borrower_personal",
                  "x-requires-permission": "referrals.contact:read",
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "exposure_after_cents": {
                  "description": "Estimated exposure now: the loan payoff minus the insurer's figure (the final settlement once there is one, else its best offer so far), never below zero. Your institution determines its GAP benefit under its own contract.",
                  "x-data-class": "borrower_personal",
                  "x-requires-permission": "referrals.contact:read",
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "exposure_reduction_cents": {
                  "description": "Estimated exposure reduced (loan payoff minus the insurer's figure): `exposure_before_cents` minus `exposure_after_cents`. Your institution determines its GAP benefit under its own contract.",
                  "x-data-class": "borrower_personal",
                  "x-requires-permission": "referrals.contact:read",
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "net_savings_cents": {
                  "x-data-class": "borrower_personal",
                  "x-requires-permission": "referrals.contact:read",
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "roi_multiple": {
                  "x-data-class": "borrower_personal",
                  "x-requires-permission": "referrals.contact:read",
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "figures_are_final": {
                  "type": "boolean",
                  "x-data-class": "public"
                },
                "savings_statement": {
                  "x-data-class": "borrower_personal",
                  "x-requires-permission": "referrals.contact:read",
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "payoff_missing": {
                  "type": "boolean",
                  "x-data-class": "public"
                }
              },
              "required": [
                "initial_offer_cents",
                "current_best_offer_cents",
                "appraised_value_cents",
                "final_settlement_cents",
                "loan_payoff_cents",
                "deductible_cents",
                "fees_paid_cents",
                "gross_uplift_cents",
                "exposure_before_cents",
                "exposure_after_cents",
                "exposure_reduction_cents",
                "net_savings_cents",
                "roi_multiple",
                "figures_are_final",
                "savings_statement",
                "payoff_missing"
              ]
            },
            {
              "type": "null"
            }
          ],
          "description": "The financial panel. Null once reporting is withdrawn (`status: reporting_withdrawn`)."
        }
      },
      "required": [
        "consultation_number",
        "days_in_appraisal",
        "timeline",
        "financial"
      ]
    }
  ],
  "$defs": {
    "Referral": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "The referral's id.",
          "x-data-class": "institution_confidential"
        },
        "object": {
          "type": "string",
          "const": "gap.referral",
          "x-data-class": "public"
        },
        "status": {
          "type": "string",
          "enum": [
            "submitted",
            "invited",
            "handoff_pending",
            "outreach_queued",
            "contact_attempted",
            "activated",
            "in_progress",
            "settled",
            "closed",
            "declined",
            "unreachable",
            "expired",
            "cancelled",
            "reporting_withdrawn"
          ],
          "description": "Where the referral stands. `reporting_withdrawn` once the borrower withdrew permission to report its progress to you, whatever happens to it after: from then on it shows the fields you supplied and no progress. New values may be added: show one you don't recognise as not yet known, and don't fail.",
          "x-data-class": "public"
        },
        "status_label": {
          "type": "string",
          "description": "The status as the portal shows it.",
          "x-data-class": "public"
        },
        "status_tone": {
          "type": "string",
          "enum": [
            "green",
            "yellow",
            "red",
            "neutral"
          ],
          "x-data-class": "public",
          "description": "New values may be added: treat one you don't recognise as unknown, and don't fail."
        },
        "status_note": {
          "description": "A third-person note on a terminal status, such as why it closed.",
          "x-data-class": "institution_confidential",
          "type": [
            "string",
            "null"
          ]
        },
        "external_ref": {
          "description": "Your own reference, as you sent it.",
          "x-data-class": "institution_confidential",
          "type": [
            "string",
            "null"
          ]
        },
        "borrower": {
          "type": "object",
          "properties": {
            "first_name": {
              "type": "string",
              "x-data-class": "borrower_personal"
            },
            "last_name": {
              "type": "string",
              "x-data-class": "borrower_personal"
            },
            "email": {
              "x-data-class": "borrower_contact",
              "x-requires-permission": "referrals.contact:read",
              "type": [
                "string",
                "null"
              ]
            },
            "phone": {
              "description": "10 digits.",
              "x-data-class": "borrower_contact",
              "x-requires-permission": "referrals.contact:read",
              "type": [
                "string",
                "null"
              ]
            }
          },
          "required": [
            "first_name",
            "last_name",
            "email",
            "phone"
          ]
        },
        "vehicle": {
          "type": "object",
          "properties": {
            "vin": {
              "x-data-class": "borrower_personal",
              "type": [
                "string",
                "null"
              ]
            },
            "year": {
              "x-data-class": "borrower_personal",
              "type": [
                "integer",
                "null"
              ]
            },
            "make": {
              "x-data-class": "borrower_personal",
              "type": [
                "string",
                "null"
              ]
            },
            "model": {
              "x-data-class": "borrower_personal",
              "type": [
                "string",
                "null"
              ]
            }
          },
          "required": [
            "vin",
            "year",
            "make",
            "model"
          ]
        },
        "claim": {
          "type": "object",
          "properties": {
            "carrier": {
              "x-data-class": "borrower_personal",
              "type": [
                "string",
                "null"
              ]
            },
            "claim_number": {
              "x-data-class": "borrower_personal",
              "type": [
                "string",
                "null"
              ]
            },
            "loss_state": {
              "x-data-class": "borrower_personal",
              "type": [
                "string",
                "null"
              ]
            },
            "date_of_loss": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Midnight UTC on the date of loss.",
              "x-data-class": "borrower_personal"
            },
            "initial_offer_cents": {
              "x-data-class": "borrower_personal",
              "type": [
                "integer",
                "null"
              ]
            }
          },
          "required": [
            "carrier",
            "claim_number",
            "loss_state",
            "date_of_loss",
            "initial_offer_cents"
          ]
        },
        "liability": {
          "type": "object",
          "properties": {
            "loan_payoff_cents": {
              "x-data-class": "borrower_personal",
              "x-requires-permission": "referrals.contact:read",
              "type": [
                "integer",
                "null"
              ]
            },
            "deductible_cents": {
              "description": "Deprecated: we stopped collecting the deductible in version 1.4.0. A referral made before then shows the deductible your institution sent until our retention schedule or an erasure clears it; any other referral shows null.",
              "x-data-class": "borrower_personal",
              "deprecated": true,
              "type": [
                "integer",
                "null"
              ]
            }
          },
          "required": [
            "loan_payoff_cents",
            "deductible_cents"
          ]
        },
        "deficiency_coverage": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "none",
                "this_institution",
                "other",
                "unknown"
              ]
            },
            {
              "type": "null"
            }
          ],
          "description": "Who covers the borrower's deficiency, as you sent it: `none`, `this_institution`, `other` or `unknown`. Null when you didn't say. When your own GAP covers the borrower (`deficiency_coverage: this_institution`), you pay our whole consultation fee for that referral, whatever your program's mode. We charge it once, when the amount of loss is determined (an award or a confirmed settlement), and the borrower pays none of it. Other costs, such as photo dispatch or a share of an umpire's fee, follow your program's rules for them. New values may be added: treat one you don't recognise as unknown, and don't fail.",
          "x-data-class": "borrower_personal"
        },
        "program": {
          "type": "object",
          "properties": {
            "mode": {
              "type": "string",
              "enum": [
                "provider_paid",
                "split_pay",
                "customer_paid",
                "membership"
              ],
              "x-data-class": "institution_confidential",
              "description": "New values may be added: treat one you don't recognise as unknown, and don't fail."
            },
            "subsidy_type": {
              "anyOf": [
                {
                  "type": "string",
                  "enum": [
                    "percent",
                    "fixed_cents"
                  ]
                },
                {
                  "type": "null"
                }
              ],
              "x-data-class": "institution_confidential",
              "description": "New values may be added: treat one you don't recognise as unknown, and don't fail."
            },
            "subsidy_value": {
              "x-data-class": "institution_confidential",
              "type": [
                "integer",
                "null"
              ]
            },
            "price_cents": {
              "type": "integer",
              "description": "Your price for this referral's consultation, in cents, fixed when the referral was submitted. `mode` and the subsidy terms decide how much of it you pay.",
              "x-data-class": "institution_confidential"
            },
            "locked": {
              "description": "True once the borrower activated under these terms; they can no longer change. Null once reporting is withdrawn (`status: reporting_withdrawn`).",
              "x-data-class": "institution_confidential",
              "type": [
                "boolean",
                "null"
              ]
            }
          },
          "required": [
            "mode",
            "subsidy_type",
            "subsidy_value",
            "price_cents",
            "locked"
          ]
        },
        "consent": {
          "type": "object",
          "properties": {
            "mode": {
              "type": "string",
              "enum": [
                "invitation",
                "warm_handoff"
              ],
              "x-data-class": "institution_confidential",
              "description": "New values may be added: treat one you don't recognise as unknown, and don't fail."
            },
            "disclosure_confirmed_at": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ],
              "description": "When your staff delivered the warm-handoff disclosure: noon UTC on the day given (`delivered_on`, or the day entered in the portal), or the moment they attested if no day was given.",
              "x-data-class": "institution_confidential"
            },
            "disclosure_channel": {
              "x-data-class": "institution_confidential",
              "type": [
                "string",
                "null"
              ]
            },
            "disclosure_attestor_name": {
              "x-data-class": "institution_confidential",
              "x-requires-permission": "referrals.contact:read",
              "type": [
                "string",
                "null"
              ]
            }
          },
          "required": [
            "mode",
            "disclosure_confirmed_at",
            "disclosure_channel",
            "disclosure_attestor_name"
          ]
        },
        "submitted_via": {
          "type": "string",
          "description": "Where the referral came from: `api`, `dashboard` or `csv`.",
          "x-data-class": "public"
        },
        "created_at": {
          "type": "string",
          "format": "date-time",
          "x-data-class": "institution_confidential"
        },
        "invited_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ],
          "x-data-class": "institution_confidential"
        },
        "invitation_expires_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ],
          "x-data-class": "institution_confidential"
        },
        "activated_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ],
          "x-data-class": "institution_confidential"
        },
        "appointed_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ],
          "description": "When the borrower appointed us as their appraiser, after our review recommended proceeding. Null until then, and once reporting is withdrawn. It returns to null if the borrower takes back telling us they sent the appointment, before an outcome is charged.",
          "x-data-class": "institution_confidential"
        },
        "settled_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ],
          "x-data-class": "institution_confidential"
        },
        "closed_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ],
          "x-data-class": "institution_confidential"
        },
        "reporting_withdrawn_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ],
          "description": "When the borrower withdrew permission to report this referral's progress to you; null while they haven't. From then on the referral shows `status: reporting_withdrawn` and no progress: its invited, expiry, activated, appointed, settled and closed times and `program.locked` are null.",
          "x-data-class": "institution_confidential"
        }
      },
      "required": [
        "id",
        "object",
        "status",
        "status_label",
        "status_tone",
        "status_note",
        "external_ref",
        "borrower",
        "vehicle",
        "claim",
        "liability",
        "deficiency_coverage",
        "program",
        "consent",
        "submitted_via",
        "created_at",
        "invited_at",
        "invitation_expires_at",
        "activated_at",
        "appointed_at",
        "settled_at",
        "closed_at",
        "reporting_withdrawn_at"
      ],
      "description": "A referral as the API returns it: snake_case, grouped sub-objects. Ignore fields you don't know. SecondAppraisal works for the borrower in the review and any appraisal. The institution determines any GAP benefit under its own contract."
    },
    "TimelineMilestone": {
      "type": "object",
      "properties": {
        "key": {
          "type": "string",
          "enum": [
            "referral_submitted",
            "borrower_invited",
            "disclosure_attested",
            "outreach_in_progress",
            "borrower_activated",
            "valuation_report_received",
            "insurance_details_received",
            "photos_received",
            "market_research",
            "preliminary_estimate_ready",
            "appraisal_report_complete",
            "authorization_received",
            "insurer_notified",
            "insurer_acknowledged",
            "insurer_appraiser_appointed",
            "appraisals_exchanged",
            "umpire_engaged",
            "award_letter_issued",
            "settlement_finalized",
            "outcome_recorded"
          ],
          "x-data-class": "public",
          "description": "New values may be added: show one you don't recognise as not yet known, and don't fail."
        },
        "label": {
          "type": "string",
          "x-data-class": "public"
        },
        "detail": {
          "type": "string",
          "x-data-class": "public"
        },
        "state": {
          "type": "string",
          "enum": [
            "complete",
            "current",
            "upcoming",
            "skipped"
          ],
          "x-data-class": "public",
          "description": "New values may be added: treat one you don't recognise as unknown, and don't fail."
        },
        "at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ],
          "description": "When the milestone completed, when known.",
          "x-data-class": "institution_confidential"
        },
        "waiting_on": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "borrower",
                "secondappraisal",
                "insurer"
              ]
            },
            {
              "type": "null"
            }
          ],
          "description": "Who the current milestone waits on. New values may be added: treat one you don't recognise as unknown, and don't fail.",
          "x-data-class": "public"
        },
        "waiting_label": {
          "x-data-class": "public",
          "type": [
            "string",
            "null"
          ]
        },
        "delayed": {
          "type": "boolean",
          "description": "True when the current milestone has run past its expected time.",
          "x-data-class": "public"
        },
        "note": {
          "description": "A third-person fact line, such as the number of contact attempts.",
          "x-data-class": "institution_confidential",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "key",
        "label",
        "detail",
        "state",
        "at",
        "waiting_on",
        "waiting_label",
        "delayed",
        "note"
      ]
    }
  }
}