import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { provideRouter } from '@angular/router';
import { AuthRepository } from '@app/domain/authentification/auth.repository';
import { AUTH_REPOSITORY_TOKEN } from '@app/infrastructure/authentification/auth-repository.token';
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
import { SettingRepository } from '@app/domain/settings/setting.repository';
import { mockSettingRepo } from '@app/testing/setting.mock';
import { SETTING_REPOSITORY_TOKEN } from '@app/infrastructure/settings/setting-repository.token';
import { ToastrService } from 'ngx-toastr';
import { mockToastR } from '@app/testing/toastr.mock';

describe('AppComponent', () => {
  let component: AppComponent;
  let fixture: ComponentFixture<AppComponent>;

  let mockAuthRepository: jest.Mocked<Partial<AuthRepository>>;
  let mockProfileRepo: jest.Mocked<Partial<ProfileRepository>>;
  let mockSettingRepository: jest.Mocked<Partial<SettingRepository>> = mockSettingRepo;

  beforeEach(async () => {
    mockAuthRepository = {
      get: jest.fn(),
      login: jest.fn(),
      sendVerificationEmail: jest.fn(),
      logout: jest.fn(),
      isAuthenticated: jest.fn(),
      isEmailVerified: jest.fn(),
      register: jest.fn(),
      sendRequestPasswordReset: jest.fn(),
      confirmPasswordReset: jest.fn(),
    };

    mockProfileRepo = {
      create: jest.fn(),
      list: jest.fn(),
      update: jest.fn(),
      getById: jest.fn(),
    };

    await TestBed.configureTestingModule({
      imports: [AppComponent],
      providers: [
        provideRouter([]),
        { provide: ToastrService, useValue: mockToastR },
        { provide: AUTH_REPOSITORY_TOKEN, useValue: mockAuthRepository },
        { provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepo },
        { provide: SETTING_REPOSITORY_TOKEN, useValue: mockSettingRepository },
      ],
    }).compileComponents();

    fixture = TestBed.createComponent(AppComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();

    await fixture.whenStable();
  });

  it('should create the app', () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.componentInstance;
    expect(app).toBeTruthy();
  });
});
