refactor(cc-dark-theme): migrate to the new DI architecture

Bug: twpowertools:226
Change-Id: I735013393d1d99cadee48399bba53a22fe59e27c
diff --git a/src/features/ccDarkTheme/ccDarkTheme.feature.ts b/src/features/ccDarkTheme/ccDarkTheme.feature.ts
deleted file mode 100644
index 74efbf2..0000000
--- a/src/features/ccDarkTheme/ccDarkTheme.feature.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import Feature from '../../common/architecture/features/Feature';
-import { ConcreteScript } from '../../common/architecture/scripts/Script';
-import { OptionCodename } from '../../common/options/optionsPrototype';
-import InjectAutoDarkTheme from './scripts/injectAutoDarkTheme.script';
-import InjectForcedDarkTheme from './scripts/injectForcedDarkTheme.script';
-import CCDarkThemeNodeWatcherScript from './scripts/nodeWatcher.script';
-
-export default class CCDarkThemeFeature extends Feature {
-  public readonly scripts: ConcreteScript[] = [
-    InjectAutoDarkTheme,
-    InjectForcedDarkTheme,
-    CCDarkThemeNodeWatcherScript,
-  ];
-
-  readonly codename = 'darkTheme';
-  readonly relatedOptions: OptionCodename[] = [
-    'ccdarktheme',
-    'ccdarktheme_mode',
-    'ccdarktheme_switch_status',
-  ];
-}
diff --git a/src/features/ccDarkTheme/nodeWatcherHandlers/ecApp.handler.ts b/src/features/ccDarkTheme/nodeWatcherHandlers/ecApp.handler.ts
index fee1ffd..355de3f 100644
--- a/src/features/ccDarkTheme/nodeWatcherHandlers/ecApp.handler.ts
+++ b/src/features/ccDarkTheme/nodeWatcherHandlers/ecApp.handler.ts
@@ -1,20 +1,23 @@
-import CssSelectorNodeWatcherScriptHandler from '../../../common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler';
+import CssSelectorNodeWatcherHandler from '../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
 import { NodeMutation } from '../../../presentation/nodeWatcher/NodeWatcherHandler';
+import { OptionsProviderPort } from '../../../services/options/OptionsProvider';
 import { injectDarkThemeButton } from '../core/logic/darkTheme';
-import { CCDarkThemeNodeWatcherDependencies } from '../scripts/nodeWatcher.script';
 
 /**
  * Injects the dark theme button.
  */
-export default class CCDarkThemeEcAppHandler extends CssSelectorNodeWatcherScriptHandler<CCDarkThemeNodeWatcherDependencies> {
+export default class CCDarkThemeEcAppHandler extends CssSelectorNodeWatcherHandler {
   cssSelector = 'ec-app';
 
+  constructor(private optionsProvider: OptionsProviderPort) {
+    super();
+  }
+
   async onMutatedNode(mutation: NodeMutation) {
     if (!(mutation.node instanceof Element)) return;
 
-    const optionsProvider = this.options.optionsProvider;
-    const isEnabled = await optionsProvider.isEnabled('ccdarktheme');
-    const mode = await optionsProvider.getOptionValue('ccdarktheme_mode');
+    const isEnabled = await this.optionsProvider.isEnabled('ccdarktheme');
+    const mode = await this.optionsProvider.getOptionValue('ccdarktheme_mode');
 
     // TODO(avm99963): make this feature dynamic.
     if (isEnabled && mode === 'switch') {
diff --git a/src/features/ccDarkTheme/nodeWatcherHandlers/reportDialog.handler.ts b/src/features/ccDarkTheme/nodeWatcherHandlers/reportDialog.handler.ts
index 42c7a59..56699e9 100644
--- a/src/features/ccDarkTheme/nodeWatcherHandlers/reportDialog.handler.ts
+++ b/src/features/ccDarkTheme/nodeWatcherHandlers/reportDialog.handler.ts
@@ -1,17 +1,25 @@
-import CssSelectorNodeWatcherScriptHandler from '../../../common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler';
+import CssSelectorNodeWatcherHandler from '../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
 import { NodeMutation } from '../../../presentation/nodeWatcher/NodeWatcherHandler';
-import { CCDarkThemeNodeWatcherDependencies } from '../scripts/nodeWatcher.script';
+import { OptionsProviderPort } from '../../../services/options/OptionsProvider';
+import ReportDialogColorThemeFix from '../core/logic/reportDialog';
 
 /**
  * Sets the report dialog iframe's theme to the appropriate theme.
  */
-export default class CCDarkThemeReportDialogHandler extends CssSelectorNodeWatcherScriptHandler<CCDarkThemeNodeWatcherDependencies> {
+export default class CCDarkThemeReportDialogHandler extends CssSelectorNodeWatcherHandler {
   cssSelector = 'iframe';
 
+  constructor(
+    private optionsProvider: OptionsProviderPort,
+    private reportDialogColorThemeFix: ReportDialogColorThemeFix,
+  ) {
+    super();
+  }
+
   onMutatedNode(mutation: NodeMutation) {
-    this.options.reportDialogColorThemeFix.fixThemeIfReportDialogIframeAndApplicable(
+    this.reportDialogColorThemeFix.fixThemeIfReportDialogIframeAndApplicable(
       mutation.node,
-      this.options.optionsProvider,
+      this.optionsProvider,
     );
   }
 }
diff --git a/src/features/ccDarkTheme/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts b/src/features/ccDarkTheme/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts
index 6343834..28b9753 100644
--- a/src/features/ccDarkTheme/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts
+++ b/src/features/ccDarkTheme/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts
@@ -1,17 +1,21 @@
-import CssSelectorNodeWatcherScriptHandler from '../../../common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler';
+import CssSelectorNodeWatcherHandler from '../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
 import { NodeMutation } from '../../../presentation/nodeWatcher/NodeWatcherHandler';
+import { OptionsProviderPort } from '../../../services/options/OptionsProvider';
 import { isDarkThemeOn } from '../core/logic/darkTheme';
 import { unifiedProfilesFix } from '../core/logic/unifiedProfiles';
-import { CCDarkThemeNodeWatcherDependencies } from '../scripts/nodeWatcher.script';
 
 /**
  * Redirect unified profile iframe to dark version if applicable
  */
-export default class CCDarkThemeUnifiedProfilesIframeHandler extends CssSelectorNodeWatcherScriptHandler<CCDarkThemeNodeWatcherDependencies> {
+export default class CCDarkThemeUnifiedProfilesIframeHandler extends CssSelectorNodeWatcherHandler {
   cssSelector = 'iframe';
 
+  constructor(private optionsProvider: OptionsProviderPort) {
+    super();
+  }
+
   async onMutatedNode(mutation: NodeMutation) {
-    const optionsValues = await this.options.optionsProvider.getOptionsValues();
+    const optionsValues = await this.optionsProvider.getOptionsValues();
 
     if (
       isDarkThemeOn(optionsValues) &&
diff --git a/src/features/ccDarkTheme/scripts/injectAutoDarkTheme.script.ts b/src/features/ccDarkTheme/scripts/injectAutoDarkTheme.script.ts
index c462a03..c1bf0a1 100644
--- a/src/features/ccDarkTheme/scripts/injectAutoDarkTheme.script.ts
+++ b/src/features/ccDarkTheme/scripts/injectAutoDarkTheme.script.ts
@@ -1,7 +1,7 @@
 import { ScriptPage } from '../../../common/architecture/scripts/Script';
 import StylesheetScript from '../../../common/architecture/scripts/stylesheet/StylesheetScript';
 
-export default class InjectAutoDarkTheme extends StylesheetScript {
+export default class CCDarkThemeInjectAutoDarkTheme extends StylesheetScript {
   stylesheet = 'ccDarkTheme.bundle.css';
   attributes = { media: '(prefers-color-scheme: dark)' };
   page = ScriptPage.CommunityConsole;
diff --git a/src/features/ccDarkTheme/scripts/injectForcedDarkTheme.script.ts b/src/features/ccDarkTheme/scripts/injectForcedDarkTheme.script.ts
index ebd221b..04c624a 100644
--- a/src/features/ccDarkTheme/scripts/injectForcedDarkTheme.script.ts
+++ b/src/features/ccDarkTheme/scripts/injectForcedDarkTheme.script.ts
@@ -1,7 +1,7 @@
 import { ScriptPage } from '../../../common/architecture/scripts/Script';
 import StylesheetScript from '../../../common/architecture/scripts/stylesheet/StylesheetScript';
 
-export default class InjectForcedDarkTheme extends StylesheetScript {
+export default class CCDarkThemeInjectForcedDarkTheme extends StylesheetScript {
   stylesheet = 'ccDarkTheme.bundle.css';
   page = ScriptPage.CommunityConsole;
 
diff --git a/src/features/ccDarkTheme/scripts/nodeWatcher.script.ts b/src/features/ccDarkTheme/scripts/nodeWatcher.script.ts
deleted file mode 100644
index 83e343e..0000000
--- a/src/features/ccDarkTheme/scripts/nodeWatcher.script.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-import DependenciesProviderSingleton, {
-  OptionsProviderDependency,
-  ReportDialogColorThemeFixDependency,
-} from '../../../common/architecture/dependenciesProvider/DependenciesProvider';
-import {
-  ScriptEnvironment,
-  ScriptPage,
-  ScriptRunPhase,
-} from '../../../common/architecture/scripts/Script';
-import LegacyNodeWatcherScript from '../../../common/architecture/scripts/nodeWatcher/LegacyNodeWatcherScript';
-import OptionsProvider from '../../../common/options/OptionsProvider';
-import ReportDialogColorThemeFix from '../core/logic/reportDialog';
-import CCDarkThemeEcAppHandler from '../nodeWatcherHandlers/ecApp.handler';
-import CCDarkThemeReportDialogHandler from '../nodeWatcherHandlers/reportDialog.handler';
-import CCDarkThemeUnifiedProfilesIframeHandler from '../nodeWatcherHandlers/unifiedProfilesIframe.handler';
-
-export interface CCDarkThemeNodeWatcherDependencies {
-  reportDialogColorThemeFix: ReportDialogColorThemeFix;
-  optionsProvider: OptionsProvider;
-}
-
-export default class CCDarkThemeNodeWatcherScript extends LegacyNodeWatcherScript<CCDarkThemeNodeWatcherDependencies> {
-  public page = ScriptPage.CommunityConsole;
-  public environment = ScriptEnvironment.ContentScript;
-  public runPhase = ScriptRunPhase.Main;
-  public handlers = new Map([
-    ['cc-dark-theme-ec-app', CCDarkThemeEcAppHandler],
-    ['cc-dark-theme-report-dialog', CCDarkThemeReportDialogHandler],
-    [
-      'cc-dark-theme-unified-profiles-iframe',
-      CCDarkThemeUnifiedProfilesIframeHandler,
-    ],
-  ]);
-
-  protected optionsFactory(): CCDarkThemeNodeWatcherDependencies {
-    const dependenciesProvider = DependenciesProviderSingleton.getInstance();
-    return {
-      reportDialogColorThemeFix: dependenciesProvider.getDependency(
-        ReportDialogColorThemeFixDependency,
-      ),
-      optionsProvider: dependenciesProvider.getDependency(
-        OptionsProviderDependency,
-      ),
-    };
-  }
-}