import { Provide, Scope, ScopeEnum } from '@midwayjs/core';

export interface FingerprintParams {
  seed?: number;
  platform?: 'Windows' | 'macOS' | 'Linux';
  platformVersion?: string;
  brand?: string;
  brandVersion?: string;
  hardwareConcurrency?: number;
  language?: string;
  timezone?: string;
}

@Provide()
@Scope(ScopeEnum.Singleton)
export class FingerprintService {
  fromSeed(seed: number): string[] {
    return this.merge({ seed });
  }

  merge(p: FingerprintParams): string[] {
    const args: string[] = [];
    if (p.seed != null) args.push(`--fingerprint=${p.seed}`);
    args.push(`--fingerprint-platform=${p.platform ?? 'Windows'}`);
    args.push(`--fingerprint-platform-version=${p.platformVersion ?? '10.0.0'}`);
    args.push(`--fingerprint-brand=${p.brand ?? 'Chrome'}`);
    if (p.brandVersion) args.push(`--fingerprint-brand-version=${p.brandVersion}`);
    args.push(`--fingerprint-hardware-concurrency=${p.hardwareConcurrency ?? 8}`);
    args.push(`--fingerprint-language=${p.language ?? 'zh-CN'}`);
    if (p.timezone) args.push(`--fingerprint-timezone=${p.timezone}`);
    return args;
  }
}
