Open ryanw-mobile opened 3 months ago
Suggest refactoring using Sealed Interface
sealed interface UnitRate
data class SingleFuel(val vatInclusiveUnitRate: Double) : UnitRate
data class DoubleFuel(
val vatInclusiveDayUnitRate: Double,
val vatInclusiveNightUnitRate: Double
) : UnitRate
fun main() {
val singleFuelRate: UnitRate = SingleFuel(0.15)
val doubleFuelRate: UnitRate = DoubleFuel(0.10, 0.12)
when (singleFuelRate) {
is SingleFuel -> {
println("Single Fuel Rate: ${singleFuelRate.vatInclusiveUnitRate}")
}
is DoubleFuel -> {
// This block will not execute for singleFuelRate, but it's here for completeness
}
}
when (doubleFuelRate) {
is SingleFuel -> {
// This block will not execute for doubleFuelRate, but it's here for completeness
}
is DoubleFuel -> {
println("Double Fuel Day Rate: ${doubleFuelRate.vatInclusiveDayUnitRate}")
println("Double Fuel Night Rate: ${doubleFuelRate.vatInclusiveNightUnitRate}")
}
}
}
In this ticket, when it happens, we also take down the VatExclusive rate because we don't need it on the UI.
This will have to be assigned the lowest priority as I know nothing about how dual rates work - from other customers' descriptions, it sounds like there are two meter readings and two rates. Hence, the handling and presentation are entirely out of scope when this project was initially crafted.
ElectricityTariffDto has placeholder added for dual rates
// @SerialName("day_unit_rate_exc_vat") val dayUnitRateExcVat: Double? = null, // @SerialName("day_unit_rate_inc_vat") val dayUnitRateIncVat: Double? = null, // @SerialName("night_unit_rate_exc_vat") val nightUnitRateExcVat: Double? = null, // @SerialName("night_unit_rate_inc_vat") val nightUnitRateIncVat: Double? = null,
Some refactoring work is needed so that we have to show an alternative layout when there are day unit rates and night unit rates.
This can be simulated by hardcoding a tariff code in the viewmodel (started with E-2R) Example Tariff: E-2R-OE-FIX-12M-24-04-11-H