{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/secondappraisal-com/json-schema/secondappraisal-com-referral-create-input-schema.json",
  "title": "ReferralCreateInput",
  "description": "One borrower referral. Rules across fields: at least one of `borrower_email` and `borrower_phone`; a split-pay `program` needs both subsidy terms; `disclosure` only with a warm handoff.",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/secondappraisal-com-openapi.json#/components/schemas/ReferralCreateInput",
  "type": "object",
  "properties": {
    "borrower_first_name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80,
      "x-data-class": "borrower_personal"
    },
    "borrower_last_name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80,
      "x-data-class": "borrower_personal"
    },
    "borrower_email": {
      "description": "An email address of at most 254 characters, with no spaces, a single `@`, and a domain with a dot that has text before it and at least two characters after it (`example.com`). Spaces around it are ignored. Stored in lowercase. At least one of `borrower_email` and `borrower_phone` is required. An invitation referral (the default `consent_mode`) needs an email while text invitations are off for its loss state: one without it is refused with 422 `email_required_sms_disabled`. A warm-handoff referral may be created phone-only, but its attestation under script 1.7 needs this address: the script's last question asks the borrower to confirm the address SecondAppraisal will email.",
      "x-data-class": "borrower_contact",
      "anyOf": [
        {
          "type": "string",
          "maxLength": 254
        },
        {
          "type": "null"
        }
      ]
    },
    "borrower_phone": {
      "description": "A 10-digit US number; punctuation and a leading 1 are tolerated, and it is stored as 10 digits. An attestation under script 1.6, which asked about this number, still needs it.",
      "x-data-class": "borrower_contact",
      "type": [
        "string",
        "null"
      ]
    },
    "consent_mode": {
      "description": "`invitation` (the default): we send the borrower a co-branded activation link. `warm_handoff`: your staff delivered the disclosure script and the borrower agreed to be contacted; send the attestation as `disclosure`. Case-insensitive.",
      "x-data-class": "institution_confidential",
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "invitation",
            "warm_handoff"
          ]
        },
        {
          "type": "null"
        }
      ],
      "default": "invitation"
    },
    "vin": {
      "description": "11 to 17 letters and digits, never I, O or Q. Case-insensitive; stored in uppercase.",
      "x-data-class": "borrower_personal",
      "type": [
        "string",
        "null"
      ]
    },
    "vehicle_year": {
      "description": "A model year from 1950 to two years after the current year.",
      "x-data-class": "borrower_personal",
      "anyOf": [
        {
          "type": "integer",
          "minimum": 1950
        },
        {
          "type": "null"
        }
      ]
    },
    "vehicle_make": {
      "x-data-class": "borrower_personal",
      "anyOf": [
        {
          "type": "string",
          "maxLength": 120
        },
        {
          "type": "null"
        }
      ]
    },
    "vehicle_model": {
      "x-data-class": "borrower_personal",
      "anyOf": [
        {
          "type": "string",
          "maxLength": 120
        },
        {
          "type": "null"
        }
      ]
    },
    "primary_carrier": {
      "description": "The borrower's insurer.",
      "x-data-class": "borrower_personal",
      "anyOf": [
        {
          "type": "string",
          "maxLength": 120
        },
        {
          "type": "null"
        }
      ]
    },
    "claim_number": {
      "description": "The borrower's claim number with that insurer.",
      "x-data-class": "borrower_personal",
      "anyOf": [
        {
          "type": "string",
          "maxLength": 120
        },
        {
          "type": "null"
        }
      ]
    },
    "loss_state": {
      "description": "The two-letter state of the loss, case-insensitive (`tx` is `TX`).",
      "x-data-class": "borrower_personal",
      "type": [
        "string",
        "null"
      ]
    },
    "garaged_state": {
      "description": "The two-letter USPS code of the state where the vehicle is garaged (a state or DC), case-insensitive. We judge this state when it is sent, else `loss_state`: a referral for a state we don't serve may be refused with 422 `state_not_served`.",
      "x-data-class": "borrower_personal",
      "type": [
        "string",
        "null"
      ]
    },
    "date_of_loss": {
      "description": "The date of the loss; at most a day ahead (a timezone ahead of UTC). Spaces around it are ignored.",
      "x-data-class": "borrower_personal",
      "anyOf": [
        {
          "type": "string",
          "format": "date"
        },
        {
          "type": "null"
        }
      ]
    },
    "initial_offer_cents": {
      "description": "The insurer's initial ACV offer, in cents.",
      "x-data-class": "borrower_personal",
      "anyOf": [
        {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000000
        },
        {
          "type": "null"
        }
      ]
    },
    "loan_payoff_cents": {
      "description": "The outstanding loan payoff, in cents. It drives your exposure figures and stays editable after activation.",
      "x-data-class": "borrower_personal",
      "anyOf": [
        {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000000
        },
        {
          "type": "null"
        }
      ]
    },
    "deductible_cents": {
      "description": "Deprecated, and ignored from version 1.4.0: we no longer ask for the borrower's deductible. A value sent is accepted and discarded; it isn't stored and doesn't change a deductible on file. Leave it out: a later version removes it.",
      "x-data-class": "borrower_personal",
      "deprecated": true,
      "anyOf": [
        {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000000
        },
        {
          "type": "null"
        }
      ]
    },
    "deficiency_coverage": {
      "description": "Who covers the borrower's deficiency, what the loan payoff leaves after the insurer pays: `none`; `this_institution`, your own GAP; `other`, someone else's GAP; or `unknown`. Omit it, or send null, if you didn't ask. Case-insensitive. 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.",
      "x-data-class": "borrower_personal",
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "none",
            "this_institution",
            "other",
            "unknown"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "external_ref": {
      "description": "Your own opaque reference, such as a case or file ID from your system; echoed in responses and webhooks. Never a loan, account or policy number (a credit union member number is an account number).",
      "x-data-class": "institution_confidential",
      "anyOf": [
        {
          "type": "string",
          "maxLength": 120
        },
        {
          "type": "null"
        }
      ]
    },
    "program": {
      "description": "Per-referral program terms. Omit, or send null, to use your program defaults.",
      "x-data-class": "institution_confidential",
      "anyOf": [
        {
          "$ref": "#/$defs/ReferralProgramInput"
        },
        {
          "type": "null"
        }
      ]
    },
    "disclosure": {
      "description": "Warm-handoff attestation, only with `consent_mode: \"warm_handoff\"`. With it the referral is created ready for our outreach; without it the referral waits for your attestation.",
      "x-data-class": "institution_confidential",
      "anyOf": [
        {
          "$ref": "#/$defs/DisclosureInput"
        },
        {
          "type": "null"
        }
      ]
    },
    "claim_against": {
      "description": "Whose insurer is handling the claim: `own` (the borrower's own insurer), `other_driver` (another driver's insurer), or `unknown`. Case-insensitive. Leave it out when you don't know.",
      "x-data-class": "borrower_personal",
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "own",
            "other_driver",
            "unknown"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "cause_of_loss": {
      "description": "The cause of the loss, if you know it. `weather` is hail, wind or a storm; a flood is `flood`. Case-insensitive.",
      "x-data-class": "borrower_personal",
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "collision",
            "theft",
            "fire",
            "flood",
            "weather",
            "vandalism",
            "animal",
            "other"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "trigger": {
      "description": "What led you to refer: `payoff_request` (an insurer asked you for the loan payoff), `loss_notice` (a notice of loss), `gap_claim` (the borrower filed a GAP claim), `borrower_request` (the borrower asked), or `other`. Case-insensitive.",
      "x-data-class": "institution_confidential",
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "payoff_request",
            "loss_notice",
            "gap_claim",
            "borrower_request",
            "other"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "payoff_requested_at": {
      "description": "When the insurer asked you for the loan payoff: a date (`2026-06-16`, read as midnight UTC) or an ISO 8601 timestamp with its UTC offset (`2026-06-16T15:04:00-06:00`). At most a day ahead.",
      "x-data-class": "institution_confidential",
      "type": [
        "string",
        "null"
      ]
    },
    "payoff_request_channel": {
      "description": "How that payoff request reached you. `web_portal` is your own online portal; `electronic_service` is a third-party payoff or letter-of-guarantee service the insurer used. Case-insensitive.",
      "x-data-class": "institution_confidential",
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "phone",
            "fax",
            "email",
            "mail",
            "web_portal",
            "electronic_service",
            "other"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "client_name": {
      "description": "For a GAP administrator: the lender or dealer whose borrower this is. At most 120 characters.",
      "x-data-class": "institution_confidential",
      "anyOf": [
        {
          "type": "string",
          "maxLength": 120
        },
        {
          "type": "null"
        }
      ]
    },
    "requirement_basis": {
      "description": "Send it only when the borrower's contract lets you require the review. It is recorded and checked against your program's bases; messages to the borrower still ask rather than require.",
      "x-data-class": "borrower_personal",
      "anyOf": [
        {
          "$ref": "#/$defs/RequirementBasisInput"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "borrower_first_name",
    "borrower_last_name"
  ],
  "additionalProperties": false,
  "$defs": {
    "DisclosureInput": {
      "type": "object",
      "properties": {
        "confirmed": {
          "type": "boolean",
          "const": true,
          "description": "Must be `true`.",
          "x-data-class": "institution_confidential"
        },
        "channel": {
          "type": "string",
          "enum": [
            "phone",
            "in_person",
            "email",
            "video",
            "other"
          ],
          "description": "How the script was delivered.",
          "x-data-class": "institution_confidential"
        },
        "attestor_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120,
          "description": "The name of the person on your staff who delivered the script.",
          "x-data-class": "institution_confidential"
        },
        "delivered_on": {
          "description": "The date the script was delivered; omit for today. At most a day ahead (a timezone ahead of UTC) and no more than 90 days old. Spaces around it are ignored.",
          "x-data-class": "institution_confidential",
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ]
        },
        "script_version": {
          "description": "The disclosure script version your staff delivered, as the script names it. The referral is stamped with it; omit it to attest the script in effect on the delivery day (today, when `delivered_on` is left out). Every institution moves to a new version together, on the date its 30-day notice names. Versions 1.0, 1.1, 1.2, 1.3, 1.4, 1.5 and 1.6 are no longer accepted, and neither is a version we never published or one whose date hadn't come on the day your staff delivered it: each is refused with 409 `script_version_stale` (a row-level error on bulk).",
          "x-data-class": "institution_confidential",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "confirmed",
        "channel",
        "attestor_name"
      ],
      "additionalProperties": false,
      "description": "Warm-handoff attestation. Accepted only with `consent_mode: \"warm_handoff\"`."
    },
    "ReferralProgramInput": {
      "type": "object",
      "properties": {
        "mode": {
          "description": "Who pays for the appraisal. Case-insensitive.",
          "x-data-class": "institution_confidential",
          "type": "string",
          "enum": [
            "provider_paid",
            "split_pay",
            "customer_paid"
          ]
        },
        "subsidy_type": {
          "description": "Split-pay only: how `subsidy_value` reads. Case-insensitive.",
          "x-data-class": "institution_confidential",
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "percent",
                "fixed_cents"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "subsidy_value": {
          "description": "Split-pay only: the percent of the fee you cover (1 to 100), or the cents you cover, per `subsidy_type`, at most 2,147,483,647. A split-pay referral needs both `subsidy_type` and a positive `subsidy_value`.",
          "x-data-class": "institution_confidential",
          "anyOf": [
            {
              "type": "integer",
              "maximum": 2147483647
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false,
      "description": "Per-referral program terms, overriding your program defaults. A mode without subsidy terms inherits your default subsidy only when it is split-pay."
    },
    "RequirementBasisInput": {
      "type": "object",
      "properties": {
        "basis_kind": {
          "description": "`contract`: a provision in the borrower's own contract. `carrier`: a GAP insurance policy's form, filed in the state, which needs `filed_form_ref`. Case-insensitive.",
          "x-data-class": "institution_confidential",
          "type": "string",
          "enum": [
            "contract",
            "carrier"
          ]
        },
        "contract_form_id": {
          "type": "string",
          "description": "The contract form's identifier, as the form names itself. 1 to 64 characters: letters, digits, spaces and . , _ - / ( ) # &. Spaces around it are ignored.",
          "x-data-class": "institution_confidential"
        },
        "contract_form_version": {
          "type": "string",
          "description": "The form's version or edition: 1 to 64 characters, in the same characters as `contract_form_id`. Spaces around it are ignored.",
          "x-data-class": "institution_confidential"
        },
        "contract_date": {
          "type": "string",
          "description": "The date of the borrower's contract (YYYY-MM-DD); at most a day ahead. Spaces around it are ignored.",
          "format": "date",
          "x-data-class": "borrower_personal"
        },
        "product_type": {
          "description": "The product the contract is: a GAP waiver or GAP insurance. Case-insensitive. A loan without GAP can't be a requirement basis: `loan_without_gap`, which versions before 1.4.0 listed, is refused, whichever version a client was built on.",
          "x-data-class": "institution_confidential",
          "type": "string",
          "enum": [
            "gap_waiver",
            "gap_insurance"
          ]
        },
        "state": {
          "description": "The two-letter USPS code of the state whose law the contract follows (a state or DC), case-insensitive.",
          "x-data-class": "borrower_personal",
          "type": "string"
        },
        "a2_acknowledged": {
          "type": "boolean",
          "description": "Whether the borrower acknowledged the signing disclosure in its own box (the program paper's Appendix A-2).",
          "x-data-class": "borrower_personal"
        },
        "adopts_x5": {
          "type": "boolean",
          "description": "Whether the contract adopts X.5 (no delay; no charges).",
          "x-data-class": "institution_confidential"
        },
        "adopts_x6": {
          "type": "boolean",
          "description": "Whether the contract adopts X.6 (no worse off).",
          "x-data-class": "institution_confidential"
        },
        "filed_form_ref": {
          "description": "A `carrier` basis's filed form: its filing reference, as an identifier of at most 64 letters, digits, dots, hyphens and underscores. Never a URL. Spaces around it are ignored.",
          "x-data-class": "institution_confidential",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "basis_kind",
        "contract_form_id",
        "contract_form_version",
        "contract_date",
        "product_type",
        "state",
        "a2_acknowledged",
        "adopts_x5",
        "adopts_x6"
      ],
      "additionalProperties": false,
      "description": "The contract basis for requiring the review. Every member is required except `filed_form_ref`, which a `carrier` basis needs."
    }
  }
}