import { Profile, ProfilePaginated } from '@app/domain/profiles/profile.model';
import { mockProfilePaginated, mockProfiles } from '@app/testing/profile.mock';
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
import { Observable, of } from 'rxjs';
import { SettingsProfileDto } from '@app/domain/profiles/dto/settings-profile.dto';

export class FakeProfileRepository implements ProfileRepository {
  list(): Observable<ProfilePaginated> {
    return of(mockProfilePaginated);
  }

  getById(profileId: string): Observable<Profile> {
    const profile = mockProfiles.find((p) => p.id === profileId) ?? ({} as Profile);
    return of(profile);
  }

  getByUserId(userId: string): Observable<Profile> {
    const profile = mockProfiles.find((p) => p.utilisateur === userId) ?? ({} as Profile);
    return of(profile);
  }

  create(profile: Profile): Observable<Profile> {
    return of(profile);
  }

  update(id: string, data: Partial<Profile>): Observable<Profile> {
    const existing = mockProfiles.find((p) => p.id === id) ?? mockProfiles[0];
    return of({ ...existing, ...data });
  }

  updateCoordinates(profileId: string, latitude: number, longitude: number): Observable<Profile> {
    const existing = mockProfiles.find((p) => p.id === profileId) ?? mockProfiles[0];
    const coordinate = { latitude, longitude };
    return of({ ...existing, coordinate });
  }

  updateSettings(profileId: string, settings: SettingsProfileDto): Observable<Profile> {
    const existing = mockProfiles.find((p) => p.id === profileId) ?? mockProfiles[0];
    const settingsData = {
      estVisible: settings.isProfilePublic,
      estGeolocaliser: settings.allowGeolocation,
      partageMail: settings.showEmail,
      partagePhone: settings.showPhone,
    };
    return of({ ...existing, settingsData });
  }
}
