/**
 * 获取中国时间字符串（YYYY-MM-DD HH:mm:ss）
 * 钉钉/宜搭 API 统一使用中国时间（Asia/Shanghai, UTC+8）
 */
export function nowChinaTimeString(): string {
  const d = new Date();
  return d.toLocaleString('sv-SE', { timeZone: 'Asia/Shanghai' }).replace('T', ' ');
}

/**
 * 格式化时间区间用于日志显示
 * 纯日期自动补全：from → 00:00:00，to → 23:59:59
 * 与 yida.service.ts 中实际传给宜搭 API 的补全规则一致
 */
export function formatTimeDisplay(
  fromTime?: string,
  toTime?: string,
): { displayFrom: string; displayTo: string } {
  const displayFrom = fromTime
    ? (fromTime.includes(':') ? fromTime.replace('T', ' ') : `${fromTime} 00:00:00`)
    : '不限';
  const displayTo = toTime
    ? (toTime.includes(':') ? toTime.replace('T', ' ') : `${toTime} 23:59:59`)
    : '不限';
  return { displayFrom, displayTo };
}
