{-# LINE 1 "src/Foreign/SwissEphemeris.hsc" #-}
{-# LANGUAGE CPP, ForeignFunctionInterface #-}

module Foreign.SwissEphemeris where

import Foreign
import Foreign.C.Types
import Foreign.C.String



newtype PlanetNumber = PlanetNumber
  { unPlanetNumber :: CInt } deriving (Eq, Show)

newtype GregFlag = GregFlag
  { unGregFlag :: CInt } deriving (Eq, Show)

newtype CalcFlag = CalcFlag
  { unCalcFlag :: CInt } deriving (Eq, Show)

-- following:
-- https://en.wikibooks.org/wiki/Haskell/FFI#Enumerations

sun   :: PlanetNumber
sun   = PlanetNumber 0
moon  :: PlanetNumber
moon  = PlanetNumber 1
mercury  :: PlanetNumber
mercury  = PlanetNumber 2
venus  :: PlanetNumber
venus  = PlanetNumber 3
mars  :: PlanetNumber
mars  = PlanetNumber 4
jupiter  :: PlanetNumber
jupiter  = PlanetNumber 5
saturn  :: PlanetNumber
saturn  = PlanetNumber 6
uranus  :: PlanetNumber
uranus  = PlanetNumber 7
neptune  :: PlanetNumber
neptune  = PlanetNumber 8
pluto  :: PlanetNumber
pluto  = PlanetNumber 9
meanNode     :: PlanetNumber
meanNode     = PlanetNumber 10
trueNode  :: PlanetNumber
trueNode  = PlanetNumber 11
meanApog  :: PlanetNumber
meanApog  = PlanetNumber 12
oscuApog  :: PlanetNumber
oscuApog  = PlanetNumber 13
earth     :: PlanetNumber
earth     = PlanetNumber 14
chiron  :: PlanetNumber
chiron  = PlanetNumber 15

{-# LINE 41 "src/Foreign/SwissEphemeris.hsc" #-}

julian  :: GregFlag
julian  = GregFlag 0
gregorian  :: GregFlag
gregorian  = GregFlag 1

{-# LINE 46 "src/Foreign/SwissEphemeris.hsc" #-}

speed  :: CalcFlag
speed  = CalcFlag 256
swissEph  :: CalcFlag
swissEph  = CalcFlag 2
equatorialPositions  :: CalcFlag
equatorialPositions  = CalcFlag 2048

{-# LINE 52 "src/Foreign/SwissEphemeris.hsc" #-}

-- functions to make the "mini" example work:

foreign import ccall unsafe "swephexp.h swe_set_ephe_path"
    c_swe_set_ephe_path :: CString -> IO ()

foreign import ccall unsafe "swephexp.h swe_close"
    c_swe_close :: IO ()

foreign import ccall unsafe "swephexp.h swe_julday"
    c_swe_julday :: CInt -- year
                 -> CInt -- month
                 -> CInt -- day 
                 -> CDouble -- hour
                 -> GregFlag
                 -> CDouble

foreign import ccall unsafe "swephexp.h swe_calc_ut"
    c_swe_calc :: CDouble
               -> PlanetNumber
               -> CalcFlag
               -> Ptr CDouble
               -> CString
               -> (IO CalcFlag)

foreign import ccall unsafe "swephexp.h swe_houses"
    c_swe_houses :: CDouble -- in fact, a Julian day "Number"
                 -> CDouble -- Lat
                 -> CDouble -- Long
                 -> CInt -- house system (see .hs version of this file)
                 -> Ptr CDouble -- cusps, 13 doubles (or 37 in system G)
                 -> Ptr CDouble -- ascmc, 10 doubles
                 -> (IO CInt)