import 'package:syncrow_web/pages/analytics/models/phases_energy_consumption.dart';
import 'package:syncrow_web/pages/analytics/params/get_energy_consumption_by_phases_param.dart';
import 'package:syncrow_web/pages/analytics/services/energy_consumption_by_phases/energy_consumption_by_phases_service.dart';
import 'package:syncrow_web/utils/helpers/safe_division_helper.dart';

class EnergyConsumptionByPhasesValueDividerDecorator
    implements EnergyConsumptionByPhasesService {
  const EnergyConsumptionByPhasesValueDividerDecorator(
    this._decoratee, {
    this.divider = 100,
  });

  final EnergyConsumptionByPhasesService _decoratee;
  final double divider;

  @override
  Future<List<PhasesEnergyConsumption>> load(
      GetEnergyConsumptionByPhasesParam param) async {
    final result = await _decoratee.load(param);
    return result.map((e) {
      return PhasesEnergyConsumption(
        date: e.date,
        energyConsumedA: SafeDivisionHelper.divide(e.energyConsumedA, divider),
        energyConsumedB: SafeDivisionHelper.divide(e.energyConsumedB, divider),
        energyConsumedC: SafeDivisionHelper.divide(e.energyConsumedC, divider),
        energyConsumedKw: SafeDivisionHelper.divide(e.energyConsumedKw, divider),
        uuid: e.uuid,
        createdAt: e.createdAt,
        updatedAt: e.updatedAt,
        deviceUuid: e.deviceUuid,
      );
    }).toList();
  }
}
