import 'package:niogu_app/core/database/app_database.dart';
import 'package:niogu_app/core/enums/member_level.dart';
import 'package:niogu_app/features/profile/domain/entities/profile.dart';
import 'package:niogu_app/features/profile/domain/repositories/i_profile_repository.dart';

class ProfileRepositoryImpl extends IProfileRepository {
  final AppDatabase _appDatabase;

  ProfileRepositoryImpl(this._appDatabase);

  @override
  Stream<double> watchProfileCompleteness() {
    return _appDatabase.userDao.watchProfileCompleteness();
  }

  @override
  Stream<double> watchBusinessCompleteness() {
    return _appDatabase.tenantDao.watchBusinessCompleteness();
  }

  @override
  Stream<double> watchOutletCompleteness() {
    return _appDatabase.outletDao.watchOutletCompleteness();
  }
  
  @override
  Stream<MemberLevel> watchMemberLevel() {
    return _appDatabase.tenantDao.watchMemberLevel();
  }

  @override
  Future<ProfileInfo> fetchProfileInfo() async {
    return await _appDatabase.userDao.getProfileInfo();
  }

  @override
  Future<int> updateProfile(UpsertProfile profile) async {
    return await _appDatabase.userDao.updateProfile(profile);
  }

  @override
  Future<BusinessInfo> fetchBusinessInfo() async {
    return await _appDatabase.tenantDao.getBusinessInfo();
  }

  @override
  Future<int> updateBusinessInfo(BusinessInfo business) async {
    return await _appDatabase.tenantDao.updateBusinessInfo(business);
  }

  @override
  Future<bool> validatePassword(String inputPassword) async {
    return await _appDatabase.userDao.validatePassword(inputPassword);
  }

  @override
  Future<int> updatePassword(String newPassword) async {
    return await _appDatabase.userDao.updatePassword(newPassword);
  }
}
