import { AuthRepository, AuthResponse } from '@app/domain/authentification/auth.repository';
import { Observable, of } from 'rxjs';
import { User } from '@app/domain/users/user.model';
import { LoginDto } from '@app/domain/authentification/dto/login-dto';
import { RegisterDto } from '@app/domain/authentification/dto/register-dto';
import { mockUsers } from '@app/testing/user.mock';

export class FakeAuthRepository implements AuthRepository {
  confirmPasswordReset(
    resetToken: string,
    newPassword: string,
    confirmPassword: string
  ): Observable<boolean> {
    return of(
      resetToken === 'fakeToken' && newPassword === confirmPassword && mockUsers[0].verified
    );
  }

  get(): User | undefined {
    return mockUsers[0];
  }

  isAuthenticated(): boolean {
    return mockUsers[0] !== undefined;
  }

  isEmailVerified(): boolean {
    return mockUsers[0].verified;
  }

  login(loginDto: LoginDto): Observable<AuthResponse> {
    const user = mockUsers.find((u) => u.email === loginDto.email);
    return of({ isValid: true, record: user, token: 'fakeToken' } as AuthResponse);
  }

  logout(): void {
    mockUsers.pop();
  }

  register(registerDto: RegisterDto): Observable<User> {
    const user = {
      ...mockUsers[0],
      id: 'fakeId',
      email: registerDto.email,
    };
    mockUsers.push(user);
    return of(user);
  }

  sendRequestPasswordReset(email: string): Observable<boolean> {
    return of(mockUsers[0].email === email);
  }

  sendVerificationEmail(email: string): Observable<boolean> {
    return of(mockUsers[0].email === email);
  }
}
