from typing import Tuple

import numpy as np
from ellipsoid_biaxial import EllipsoidBiaxial
from numpy import cos, sin, tan
from numpy.typing import NDArray

import runge_kutta as rk


def gha1(re: EllipsoidBiaxial, phi0: float, lamb0: float, alpha0: float, s: float, num: int) -> Tuple[float, float, float]:
    """
    Berechnung der 1. GHA auf einem Rotationsellipsoid mittels RK4
    :param re:
    :param phi0:
    :param lamb0:
    :param alpha0:
    :param s:
    :param num:
    :return:
    """
    def buildODE():
        def ODE(s: float, v: NDArray):
            phi, lam, A = v
            V = re.V(phi)
            dphi = cos(A) * V ** 3 / re.c
            dlam = sin(A) * V / (cos(phi) * re.c)
            dA = tan(phi) * sin(A) * V / re.c
            return np.array([dphi, dlam, dA])
        return ODE

    _, funktionswerte = rk.rk4(buildODE(), 0, np.array([phi0, lamb0, alpha0]), s, num)
    return funktionswerte[-1][0], funktionswerte[-1][1], funktionswerte[-1][2]
