/**
 * Parse duration strings like "2h", "7d", "3600s", "30m", or a bare number-of-seconds.
 * Returns seconds. Used to feed @nestjs/jwt's `expiresIn` as a numeric value
 * (their typed contract no longer accepts arbitrary strings).
 */
export function parseDurationToSeconds(input: string): number {
  const m = /^(\d+)\s*([smhd])?$/.exec(input.trim());
  if (!m || !m[1]) return 7200;
  const n = Number(m[1]);
  switch (m[2]) {
    case 'm':
      return n * 60;
    case 'h':
      return n * 3600;
    case 'd':
      return n * 86400;
    case 's':
    case undefined:
    default:
      return n;
  }
}
