// Логгер для Service Worker
// IN-02 fix: migrated from `...args: any[]` to `...args: unknown[]` so
// the type signature matches OffscreenLogger and aligns with strict-
// mode hygiene. console.log accepts unknown[] natively (its variadic
// signature is `(...data: any[]) => void`, so passing unknown values
// works fine — the underlying console.* coerces with String() / object
// inspection). Call sites at content/popup/background passed already-
// typed values, so no widening was required.
export class Logger {
  private context: string;

  constructor(context: string) {
    this.context = context;
  }

  private logWithLevel(level: 'log' | 'warn' | 'error', ...args: unknown[]) {
    const timestamp = new Date().toISOString();
    console[level](`[SW:${this.context}] ${timestamp}`, ...args);
  }

  log(...args: unknown[]) {
    this.logWithLevel('log', ...args);
  }

  warn(...args: unknown[]) {
    this.logWithLevel('warn', ...args);
  }

  error(...args: unknown[]) {
    this.logWithLevel('error', ...args);
  }
}

// Логгер для Content Script (IN-02 fix: see Logger above)
export class ContentLogger {
  private context: string;

  constructor(context: string) {
    this.context = context;
  }

  private logWithLevel(level: 'log' | 'warn' | 'error', ...args: unknown[]) {
    const timestamp = new Date().toISOString();
    console[level](`[CS:${this.context}] ${timestamp}`, ...args);
  }

  log(...args: unknown[]) {
    this.logWithLevel('log', ...args);
  }

  warn(...args: unknown[]) {
    this.logWithLevel('warn', ...args);
  }

  error(...args: unknown[]) {
    this.logWithLevel('error', ...args);
  }
}

// Логгер для Offscreen Document
// All three loggers now share the same `...args: unknown[]` signature
// (IN-02 fix retired the style divergence noted in plan 01-03).
export class OffscreenLogger {
  private context: string;

  constructor(context: string) {
    this.context = context;
  }

  private logWithLevel(level: 'log' | 'warn' | 'error', ...args: unknown[]) {
    const timestamp = new Date().toISOString();
    console[level](`[OS:${this.context}] ${timestamp}`, ...args);
  }

  log(...args: unknown[]) {
    this.logWithLevel('log', ...args);
  }

  warn(...args: unknown[]) {
    this.logWithLevel('warn', ...args);
  }

  error(...args: unknown[]) {
    this.logWithLevel('error', ...args);
  }
}