package ballistics.orbitalPoints.integrator

import ballistics.orbitalPoints.integrator.modDv.AbstractMDV
import ballistics.orbitalPoints.integrator.modDv.MDVBars
import ballistics.orbitalPoints.integrator.modDv.MDVFoto
import ballistics.orbitalPoints.integrator.modDv.MDVKondor
import ballistics.types.AstroType
import ballistics.types.BallisticsError
import ballistics.types.EarthType
import ballistics.types.ModDVType

internal abstract class AbstractIntegrator(var mdType: ModDVType, earthType: EarthType) {
    protected val a = arrayOf(1, 2, 2, 1)
    protected val prav: AbstractMDV
    var step = 60.0
    val y = arrayOf(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

    init {
        when (mdType) {
            ModDVType.FOTO -> prav = MDVFoto(earthType)
            ModDVType.METEORM1 -> prav = MDVKondor(earthType, AstroType.ATJ2000, 8, true)
            ModDVType.METEORM2 -> prav = MDVKondor(earthType, AstroType.ATJ2000, 8, true)
            ModDVType.KONDOR -> prav = MDVKondor(earthType, AstroType.ATJ2000, 24, false)
            ModDVType.KONDOR_PROGNOZ -> prav = MDVKondor(earthType, AstroType.ATJ2000, 24, true)
            ModDVType.BARS -> prav = MDVBars(earthType)
        }
    }

    abstract fun nextStep(x: Array<Double>): BallisticsError

    abstract fun accelerate(x: Array<Double>): BallisticsError

    abstract fun setSBall(s: Double)

    fun setF81(f81: Double) {
        prav.f81 = if (f81 < 25.0) 25.0 else f81
    }
}
