import 'dart:developer';

import 'package:enaklo_pos/presentation/home/models/outlet_model.dart';
import 'package:shared_preferences/shared_preferences.dart';

class OutletLocalDatasource {
  Future<void> save(Outlet outlet) async {
    try {
      final prefs = await SharedPreferences.getInstance();
      await prefs.setString('outlet', outlet.toJson());
      log('Outlet Local Data: ${outlet.toJson()}');
    } catch (e) {
      log('Error saving outlet: $e');
    }
  }

  Future<void> remove() async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.remove('outlet');
  }

  Future<Outlet> get() async {
    final prefs = await SharedPreferences.getInstance();
    final outlet = prefs.getString('outlet');

    log('Outlet Local Data: $outlet');

    return Outlet.fromJson(outlet!);
  }
}
