# refund_full — FRIDAY 整单冲减退费(status=4 反向单 + status=3 负金额单;导出侧 WHERE 切分)
# 实测:status=4 共 99 单全带 ref_settlement_id(挂原结算单)、金额全负;
#   2ac96f6d 品牌不用 status=4,整单冲减记 status=3 负金额(200 单,多无 ref → paymentExternalId=null)。
# ⭐ paymentExternalId = ref_settlement_id —— jvs-dw 缺此字段只能 registration_id 侧面对账,
#    FRIDAY 直接兑现 refund.yaml 里预留的升级(退费精确挂回原 payment fact)。
# 金额负值由 refund parser Math.abs 归一为正 cents(语义=患者拿回的钱,host 无关)。
canonical: refund

emits:
  action: refund_created
  subjectType: refund
  occurredAtField: refundedAt
  kind: actual

primary:
  table: refund_full_rows        # transforms 产出:status=4 ∪ (status=3 且 receivable<0)
  key: uuid
  dedup_by: uuid

field_mapping:
  externalId:          uuid
  updatedAt:           updated_gmt_at
  createdAt:           created_gmt_at
  patientExternalId:   patient_id
  clinicId:            organization_id
  refundedAt:          created_gmt_at
  amount:              net_receipts_this    # 负值,parser abs 归一
  paymentExternalId:   ref_settlement_id    # ⭐ 原结算单(= payment.externalId)
  reason:              reason
  encounterExternalId: registration_id
