import 'package:syncrow_web/pages/analytics/models/energy_data_model.dart';
import 'package:syncrow_web/pages/analytics/params/get_total_energy_consumption_param.dart';
import 'package:syncrow_web/pages/analytics/services/total_energy_consumption/total_energy_consumption_service.dart';
import 'package:syncrow_web/utils/helpers/safe_division_helper.dart';

class DividedTotalEnergyConsumptionDecorator
    implements TotalEnergyConsumptionService {
  const DividedTotalEnergyConsumptionDecorator(
    this._decoratee, {
    this.divider = 100,
  });

  final TotalEnergyConsumptionService _decoratee;
  final double divider;

  @override
  Future<List<EnergyDataModel>> load(GetTotalEnergyConsumptionParam param) async {
    final result = await _decoratee.load(param);
    return result.map((e) {
      return EnergyDataModel(
        date: e.date,
        value: SafeDivisionHelper.divide(e.value, divider),
      );
    }).toList();
  }
}
