/**
 * Test d'intégration des nouveaux services pour vérifier leur fonctionnement
 * Services modernes remplaçant l'ancien GlobalService
 */

import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { AuthenticationService } from './authentication.service';
import { DataService } from './data.service';
import { HttpClientService } from './http-client.service';
import { CacheService } from './cache.service';
import { ConfigurationService } from './configuration.service';

describe('Services Integration Test', () => {
  let authService: AuthenticationService;
  let dataService: DataService;
  let httpService: HttpClientService;
  let cacheService: CacheService;
  let configService: ConfigurationService;

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [HttpClientTestingModule],
      providers: [
        AuthenticationService,
        DataService,
        HttpClientService,
        CacheService,
        ConfigurationService
      ]
    });

    authService = TestBed.inject(AuthenticationService);
    dataService = TestBed.inject(DataService);
    httpService = TestBed.inject(HttpClientService);
    cacheService = TestBed.inject(CacheService);
    configService = TestBed.inject(ConfigurationService);
  });

  it('✅ Tous les services doivent être créés', () => {
    expect(authService).toBeTruthy();
    expect(dataService).toBeTruthy();
    expect(httpService).toBeTruthy();
    expect(cacheService).toBeTruthy();
    expect(configService).toBeTruthy();
  });

  it('✅ CacheService doit fonctionner', () => {
    const testKey = 'test-key';
    const testValue = { data: 'test' };
    
    // Test set/get
    cacheService.set(testKey, testValue);
    const cachedValue = cacheService.get(testKey);
    
    expect(cachedValue).toEqual(testValue);
  });

  it('✅ ConfigurationService doit retourner la configuration', () => {
    const uiConfig = configService.getUIConfig();
    const fullConfig = configService.currentConfig;

    expect(uiConfig).toBeTruthy();
    expect(uiConfig.theme).toBeTruthy();
    expect(fullConfig).toBeTruthy();
    expect(fullConfig.api).toBeTruthy();
    expect(fullConfig.api.baseUrl).toBeTruthy();
  });

  it('✅ AuthenticationService doit gérer les états', () => {
    const isLoggedIn = authService.isLoggedIn();
    
    // Par défaut, l'utilisateur n'est pas connecté
    expect(typeof isLoggedIn).toBe('boolean');
  });

  it('✅ DataService doit avoir les bonnes méthodes', () => {
    expect(typeof dataService.getAll).toBe('function');
    expect(typeof dataService.getById).toBe('function');
    expect(typeof dataService.create).toBe('function');
    expect(typeof dataService.update).toBe('function');
    expect(typeof dataService.delete).toBe('function');
    expect(typeof dataService.getPagedData).toBe('function');
  });

  it('✅ HttpClientService doit avoir les bonnes méthodes', () => {
    expect(typeof httpService.get).toBe('function');
    expect(typeof httpService.post).toBe('function');
    expect(typeof httpService.put).toBe('function');
    expect(typeof httpService.delete).toBe('function');
    expect(typeof httpService.request).toBe('function');
  });
});