import '../../domain/entities/standing_order.dart';
import '../../domain/repositories/standing_orders_repository.dart';
import '../datasources/standing_orders_datasource.dart';

class StandingOrdersRepositoryImpl implements StandingOrdersRepository {
  final StandingOrdersDatasource _datasource;

  StandingOrdersRepositoryImpl(this._datasource);

  @override
  Future<List<StandingOrder>> getAll() async {
    final models = await _datasource.fetchAll();
    return models.map((m) => m.toEntity()).toList();
  }

  @override
  Future<StandingOrder> getById(String id) async {
    final model = await _datasource.fetchById(id);
    return model.toEntity();
  }

  @override
  Future<StandingOrder> create(Map<String, dynamic> data) async {
    final model = await _datasource.create(data);
    return model.toEntity();
  }

  @override
  Future<StandingOrder> update(String id, Map<String, dynamic> updates) async {
    final model = await _datasource.update(id, updates);
    return model.toEntity();
  }

  @override
  Future<void> delete(String id) async {
    await _datasource.delete(id);
  }

  @override
  Future<StandingOrder> toggleActive(String id, bool isActive) async {
    final model = await _datasource.toggleActive(id, isActive);
    return model.toEntity();
  }
}
