import 'dart:developer';

import 'package:injectable/injectable.dart';
import 'package:krow/core/data/models/staff/staff.dart';
import 'package:krow/features/profile/personal_info/data/staff_api_source.dart';
import 'package:krow/features/profile/personal_info/data/staff_repository.dart';

@Singleton(as: StaffPersonalInfoRepository)
class StaffPersonalInfoRepositoryImpl implements StaffPersonalInfoRepository {
  StaffPersonalInfoRepositoryImpl({
    required StaffPersonalInfoApiProvider staffApi,
  }) : _staffApi = staffApi;

  final StaffPersonalInfoApiProvider _staffApi;

  @override
  Stream<Staff> getPersonalInfo() {
    return _staffApi.getMeWithCache();
  }

  @override
  Future<Staff> updatePersonalInfo({
    required String firstName,
    required String? middleName,
    required String lastName,
    required String email,
    String? avatarPath,
  }) {
    try {
      return _staffApi.updateStaffPersonalInfo(
        firstName: firstName,
        middleName: middleName,
        lastName: lastName,
        email: email,
        avatarPath: avatarPath,
      );
    } catch (exception) {
      log((exception as Error).stackTrace.toString());
      rethrow;
    }
  }
}
