{-|
Module      : Functions for encoding Hasklepias Feature data
Description : Defines ToJSON instances for Features.
Copyright   : (c) NoviSci, Inc 2020
License     : BSD3
Maintainer  : bsaul@novisci.com
-}

{-# LANGUAGE OverloadedStrings #-}

module Hasklepias.Types.Feature.Aeson(
) where

import IntervalAlgebra
import GHC.Generics
import Hasklepias.Types.Feature ( MissingReason, Feature(..) )
import Data.Aeson
--  ( ToJSON, toJSON )

instance (ToJSON a, Ord a, Show a)=> ToJSON (Interval a) where
    toJSON :: Interval a -> Value
toJSON Interval a
x = 
        [Pair] -> Value
object [Text
"begin" Text -> a -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Interval a -> a
forall (i :: * -> *) a. Intervallic i a => i a -> a
begin Interval a
x, Text
"end" Text -> a -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Interval a -> a
forall (i :: * -> *) a. Intervallic i a => i a -> a
end Interval a
x]
instance ToJSON MissingReason 
instance (ToJSON d)=> ToJSON (Feature d) where
    toJSON :: Feature d -> Value
toJSON  Feature d
x = case Feature d -> Either MissingReason d
forall d. Feature d -> Either MissingReason d
getFeature Feature d
x of 
      (Left MissingReason
l)  -> MissingReason -> Value
forall a. ToJSON a => a -> Value
toJSON MissingReason
l
      (Right d
r) -> d -> Value
forall a. ToJSON a => a -> Value
toJSON d
r