import 'package:niogu_app/core/database/app_database.dart' hide Outlet;
import 'package:niogu_app/features/outlets/domain/entities/outlet.dart';
import 'package:niogu_app/features/outlets/domain/repositories/i_outlet_repository.dart';
import 'package:niogu_app/features/stock_in/domain/entities/stock_in_transfer.dart';

class OutletRepositoryImpl implements IOutletRepository {
  final AppDatabase _appDatabase;

  OutletRepositoryImpl(this._appDatabase);

  @override
  Future<bool> fetchIsMainOutlet() async {
    return await _appDatabase.outletDao.getIsMainOutlet();
  }

  @override
  Stream<List<UserDeletedByOutlet>> watchUserDeletedByOutlet() {
    return _appDatabase.outletDao.watchUserDeletedByOutlet();
  }

  @override
  Stream<int> watchLimitOutlet() {
    return _appDatabase.outletDao.watchLimitAddOutlet();
  }

  @override
  Stream<List<DisplayOutlet>> watchDisplayOutlets() {
    return _appDatabase.outletDao.watchAllDisplayOutlets();
  }

  @override
  Future<OutletDetail> getOutletById(String id) async {
    return await _appDatabase.outletDao.getOutletById(id);
  }

  @override
  Future<MainOutlet> getMainOutlet() async {
    return await _appDatabase.outletDao.getMainOutlet();
  }

  @override
  Stream<List<StaffAdminDetail>> watchStaffAdmins(String outletId) {
    return _appDatabase.outletDao.watchAllStaffAdmins(outletId);
  }

  @override
  Future<bool> validatePhoneAndEmail({
    required String phoneNumber,
    String? email,
    String? excludeId,
  }) async {
    return await _appDatabase.outletDao.validatePhoneAndEmail(
      phoneNumber: phoneNumber,
      email: email,
      excludeId: excludeId,
    );
  }

  @override
  Future<bool> validateAddUserStaff({
    required String firstPhoneNumber,
    required String firstEmail,
    String? secondPhoneNumber,
    String? secondEmail,
  }) async {
    return await _appDatabase.outletDao.validateAddUserStaff(
      firstPhoneNumber: firstPhoneNumber,
      firstEmail: firstEmail,
      secondPhoneNumber: secondPhoneNumber,
      secondEmail: secondEmail,
    );
  }

  @override
  Future<void> saveStaffAdmin({
    required String outletId,
    UpsertStaffAdmin? firstStaffAdmin,
    UpsertStaffAdmin? secondStaffAdmin,
  }) async {
    await _appDatabase.outletDao.saveStaffAdmin(
      outletId: outletId,
      firstStaffAdmin: firstStaffAdmin,
      secondStaffAdmin: secondStaffAdmin,
    );
  }

  @override
  Future<void> deleteOutlet(String outletId) async {
    await _appDatabase.outletDao.deleteOutlet(outletId);
  }

  @override
  Future<int> deleteStaffAdmin(String userId) async {
    return await _appDatabase.outletDao.deleteStaffAdmin(userId);
  }

  @override
  Future<void> saveOutlet(UpsertOutlet upsertOutlet) async {
    await _appDatabase.outletDao.saveOutlet(upsertOutlet);
  }

  @override
  Stream<List<Outlet>> watchOutlets() {
    return _appDatabase.outletDao.watchAllOutlets();
  }

  @override
  Stream<List<SourceOutlet>> watchSourceOutlets(
    String currentOutletId,
    bool isShowAll,
  ) {
    return _appDatabase.outletDao.watchAllSourceOutlets(isShowAll);
  }
}
