{-|
Module      : AstroData
Description : Initial starting astronomy data

-}

{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}

module AstroData
       (
         OrbitBody(..)
       , obPos
       , obVel
       , updateSvecs
       , formatDoubleOB
       ) where

import PhysicsVectors
import Text.Printf(printf)
import GHC.Generics (Generic)
import Control.DeepSeq(NFData)

-- | Orbital body type storing the Body ID, GM parameter, position-velocity vector, and epoch
-- Note that units are in au days and epoch is normally measured from Julian -- epoch
data OrbitBody f = OrbitBody { bid :: String, bGM :: f, brv :: Vec2 f, epoch :: f}
  deriving (Eq, Show, Generic, NFData)

obPos :: Floating f => OrbitBody f -> Vec3 f
obPos = r . brv

obVel :: Floating f => OrbitBody f -> Vec3 f
obVel = v . brv

updateSvecs :: Floating f => OrbitBody f -> f -> Vec2 f -> OrbitBody f
updateSvecs body dt rvn = OrbitBody (bid body) (bGM body) rvn (epoch body + dt)

formatDoubleOB :: OrbitBody Double -> String
formatDoubleOB (OrbitBody bid' _ (Vec2 r' v') t) = printf "%v, %v, %v, %v" bid' t (formatVec r') (formatVec v')
  where
    formatVec :: Vec3 Double -> String
    formatVec (Vec3 a b c) = printf "%v, %v, %v" a b c