import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:niogu_app/core/entities/custom_activity.dart';
import 'package:niogu_app/core/providers/app_provider.dart';
import 'package:niogu_app/features/user/data/repositories/user_repository_impl.dart';
import 'package:niogu_app/features/user/domain/entities/user.dart';
import 'package:niogu_app/features/user/domain/repositories/i_user_repository.dart';

final userRepositoryProvider = Provider.autoDispose<IUserRepository>((ref) {
  final appDatabase = ref.watch(appDatabaseProvider);
  return UserRepositoryImpl(appDatabase);
});

final shiftInfoStreamProvider = StreamProvider.autoDispose<ShiftInfo>((ref) {
  final userRepository = ref.watch(userRepositoryProvider);

  return userRepository.watchShiftInfo();
});

final permissionActivityStreamProvider = StreamProvider<MessageActivity?>((ref) {
  final userRepository = ref.watch(userRepositoryProvider);

  final currentOutletId = ref.watch(currentOutletIdProvider);

  if(currentOutletId == null) {
    return Stream<MessageActivity?>.value(null);
  }

  return userRepository.checkPermissionActivity(currentOutletId);
});
