import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../core/sync/sync_engine.dart';
import '../cart/cart_state.dart' show apiClientProvider;
import 'hr_api.dart';

class HrSession {
  const HrSession({required this.cafeId, required this.employeeId});
  final String cafeId;
  final String employeeId;
}

const _demoCafeId = 'cafe_demo_001';
const _demoEmployeeId = 'emp_demo_owner';

final hrApiProvider = Provider<HrApi>((ref) => HrApi(ref.watch(apiClientProvider)));

final syncEngineProvider = Provider<SyncEngine>((ref) => SyncEngine());

final hrSessionProvider = Provider<HrSession?>(
  (_) => const HrSession(cafeId: _demoCafeId, employeeId: _demoEmployeeId),
);

final todayShiftProvider = FutureProvider<Map<String, dynamic>?>((ref) async {
  final session = ref.watch(hrSessionProvider);
  if (session == null) return null;
  return ref.watch(hrApiProvider).fetchTodayShift(
        cafeId: session.cafeId,
        employeeId: session.employeeId,
      );
});
