/** 从 ICustomer 富字段解析展示名（与 SalesSdk getClientName 语义对齐）。 */
function resolveCustomerDisplayName(customer) {
  var _customer$name;
  var c = customer;
  var displayName = c.display_name;
  if (typeof displayName === 'string' && displayName) return displayName;
  var nickname = c.nickname;
  if (typeof nickname === 'string' && nickname) return nickname;
  var firstName = c.first_name;
  var lastName = c.last_name;
  if (typeof firstName === 'string' && firstName || typeof lastName === 'string' && lastName) {
    return "".concat(typeof firstName === 'string' ? firstName : '', " ").concat(typeof lastName === 'string' ? lastName : '').trim();
  }
  var customerName = c.customer_name;
  if (typeof customerName === 'string' && customerName) return customerName;
  return (_customer$name = customer.name) !== null && _customer$name !== void 0 ? _customer$name : '';
}

/** 将 ICustomer 格式化为写入 tempOrder 的协议字段。 */
export function formatOrderCustomerPatch(customer) {
  var _customer$phone, _customer$email, _country_calling_code, _country_calling_code2;
  var rawId = customer.id;
  var numericId = typeof rawId === 'number' ? rawId : rawId !== undefined && rawId !== null && rawId !== '' ? Number(rawId) : null;
  return {
    customer_id: Number.isFinite(numericId) ? numericId : null,
    customer_name: resolveCustomerDisplayName(customer),
    phone: (_customer$phone = customer.phone) !== null && _customer$phone !== void 0 ? _customer$phone : '',
    email: (_customer$email = customer.email) !== null && _customer$email !== void 0 ? _customer$email : '',
    country_calling_code: (_country_calling_code = (_country_calling_code2 = customer.country_calling_code) === null || _country_calling_code2 === void 0 ? void 0 : _country_calling_code2.toString()) !== null && _country_calling_code !== void 0 ? _country_calling_code : ''
  };
}