import { createHash } from 'node:crypto';

export function generateChuanglanSign(
  password: string,
  params: Record<string, string | undefined>,
): string {
  const raw = Object.keys(params)
    .sort()
    .reduce((acc, key) => {
      const value = params[key];
      if (value != null && value.trim() !== '') {
        return acc + key + value;
      }
      return acc;
    }, '');

  return createHash('md5').update(raw + password, 'utf8').digest('hex').toLowerCase();
}
