# refund_item — FRIDAY 行级部分退费(patient_settlement_spec is_refund=1,导出已收窄)
# 实测:581 行全部归属 status=3 头单(部分退费轨道);金额正值 = 被退金额(同 jvs-dw ①语义)。
# 头单本身仍作 payment(原始消费),本资源扣减 → LTV 对账闭合。
# paymentExternalId = settlement_id(所属结算头单 = payment.externalId)。
canonical: refund

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

primary:
  table: refund_item_rows        # transforms 产出:patient_settlement_spec 里 is_refund=1
  key: id
  dedup_by: id

field_mapping:
  externalId:          id
  updatedAt:           updated_gmt_at
  createdAt:           created_gmt_at
  # spec.patient_id 部分品牌原是诊所本地 id → 宿主导出时已从结算头反填真 patient_id(inline);PAC 直接用
  patientExternalId:   patient_id
  clinicId:            organization_id
  refundedAt:          created_gmt_at
  amount:              net_receipts_this
  paymentExternalId:   settlement_id        # 所属结算头单(部分退费挂回原 payment)
  # 被退项目名(passthrough,UI 时间轴"退费 ¥X(项目 Y)")
  refundProjectName:   service_project_name
