import 'dart:developer';

import 'package:injectable/injectable.dart';
import 'package:krow/core/data/models/client/client.dart';
import 'package:krow/features/profile/data/profile_api_source.dart';
import 'package:krow/features/profile/data/profile_repository.dart';

@Singleton(as: ClientProfileRepository)
class ClientProfileRepositoryImpl implements ClientProfileRepository {
  ClientProfileRepositoryImpl({
    required ClientProfileApiProvider apiProvider,
  }) : _apiProvider = apiProvider;

  final ClientProfileApiProvider _apiProvider;

  @override
  Stream<ClientModel> getPersonalInfo() {
    return _apiProvider.getMeWithCache();
  }

  @override
  Future<ClientModel> updatePersonalInfo({
    required String firstName,
    required String lastName,
    required String phone,
    String? avatarPath,
  }) {
    try {
      return _apiProvider.updatePersonalInfo(
        firstName: firstName,
        lastName: lastName,
        phone: phone,
        avatarPath: avatarPath,
      );
    } catch (exception) {
      log((exception as Error).stackTrace.toString());
      rethrow;
    }
  }

  @override
  Future<void> deactivateProfile() {
    return _apiProvider.deactivateClientProfile();
  }
}
