import { InjectionToken, inject } from '@angular/core';
import { BackofficeDataProvider } from './providers/backoffice-data-provider.interface';
import { MockBackofficeDataProvider } from './providers/mock-backoffice-data.provider';
import { ApiBackofficeDataProvider } from './providers/api-backoffice-data.provider';
import { RuntimeProviderStrategyService } from '../providers/runtime-provider-strategy.service';

export const BACKOFFICE_DATA_PROVIDER = new InjectionToken<BackofficeDataProvider>('BACKOFFICE_DATA_PROVIDER', {
  providedIn: 'root',
  factory: () => {
    const strategy = inject(RuntimeProviderStrategyService);
    const mockProvider = inject(MockBackofficeDataProvider);
    const apiProvider = inject(ApiBackofficeDataProvider);

    switch (strategy.getBackofficeProviderMode()) {
      case 'mock':
        return mockProvider;
      case 'remote-config':
      case 'api':
      default:
        return apiProvider;
    }
  }
});
