{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}

{- |
Module      :  OpenTelemetry.Attributes.Attribute
Copyright   :  (c) Ian Duncan, 2021
License     :  BSD-3
Description :  Metadata values
Maintainer  :  Ian Duncan
Stability   :  experimental
Portability :  non-portable (GHC extensions)
-}
module OpenTelemetry.Attributes.Attribute (
  Attribute (..),
  ToAttribute (..),
  FromAttribute (..),
  PrimitiveAttribute (..),
  ToPrimitiveAttribute (..),
  FromPrimitiveAttribute (..),
) where

import Data.Data (Data)
import Data.Hashable (Hashable)
import Data.Int (Int64)
import qualified Data.List as L
import Data.String (IsString (..))
import Data.Text (Text)
import GHC.Generics (Generic)
import qualified Language.Haskell.TH.Syntax as TH
import Prelude hiding (lookup, map)


-- | Convert a Haskell value to a 'PrimitiveAttribute' value.
class ToPrimitiveAttribute a where
  toPrimitiveAttribute :: a -> PrimitiveAttribute


class FromPrimitiveAttribute a where
  fromPrimitiveAttribute :: PrimitiveAttribute -> Maybe a


{- | An attribute represents user-provided metadata about a span, link, or event.

 Telemetry tools may use this data to support high-cardinality querying, visualization
 in waterfall diagrams, trace sampling decisions, and more.
-}
data Attribute
  = -- | An attribute representing a single primitive value
    AttributeValue PrimitiveAttribute
  | -- | An attribute representing an array of primitive values.
    --
    -- All values in the array MUST be of the same primitive attribute type.
    AttributeArray [PrimitiveAttribute]
  deriving stock (ReadPrec [Attribute]
ReadPrec Attribute
Int -> ReadS Attribute
ReadS [Attribute]
(Int -> ReadS Attribute)
-> ReadS [Attribute]
-> ReadPrec Attribute
-> ReadPrec [Attribute]
-> Read Attribute
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Attribute
readsPrec :: Int -> ReadS Attribute
$creadList :: ReadS [Attribute]
readList :: ReadS [Attribute]
$creadPrec :: ReadPrec Attribute
readPrec :: ReadPrec Attribute
$creadListPrec :: ReadPrec [Attribute]
readListPrec :: ReadPrec [Attribute]
Read, Int -> Attribute -> ShowS
[Attribute] -> ShowS
Attribute -> String
(Int -> Attribute -> ShowS)
-> (Attribute -> String)
-> ([Attribute] -> ShowS)
-> Show Attribute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Attribute -> ShowS
showsPrec :: Int -> Attribute -> ShowS
$cshow :: Attribute -> String
show :: Attribute -> String
$cshowList :: [Attribute] -> ShowS
showList :: [Attribute] -> ShowS
Show, Attribute -> Attribute -> Bool
(Attribute -> Attribute -> Bool)
-> (Attribute -> Attribute -> Bool) -> Eq Attribute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Attribute -> Attribute -> Bool
== :: Attribute -> Attribute -> Bool
$c/= :: Attribute -> Attribute -> Bool
/= :: Attribute -> Attribute -> Bool
Eq, Eq Attribute
Eq Attribute =>
(Attribute -> Attribute -> Ordering)
-> (Attribute -> Attribute -> Bool)
-> (Attribute -> Attribute -> Bool)
-> (Attribute -> Attribute -> Bool)
-> (Attribute -> Attribute -> Bool)
-> (Attribute -> Attribute -> Attribute)
-> (Attribute -> Attribute -> Attribute)
-> Ord Attribute
Attribute -> Attribute -> Bool
Attribute -> Attribute -> Ordering
Attribute -> Attribute -> Attribute
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Attribute -> Attribute -> Ordering
compare :: Attribute -> Attribute -> Ordering
$c< :: Attribute -> Attribute -> Bool
< :: Attribute -> Attribute -> Bool
$c<= :: Attribute -> Attribute -> Bool
<= :: Attribute -> Attribute -> Bool
$c> :: Attribute -> Attribute -> Bool
> :: Attribute -> Attribute -> Bool
$c>= :: Attribute -> Attribute -> Bool
>= :: Attribute -> Attribute -> Bool
$cmax :: Attribute -> Attribute -> Attribute
max :: Attribute -> Attribute -> Attribute
$cmin :: Attribute -> Attribute -> Attribute
min :: Attribute -> Attribute -> Attribute
Ord, Typeable Attribute
Typeable Attribute =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Attribute -> c Attribute)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Attribute)
-> (Attribute -> Constr)
-> (Attribute -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Attribute))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Attribute))
-> ((forall b. Data b => b -> b) -> Attribute -> Attribute)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Attribute -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Attribute -> r)
-> (forall u. (forall d. Data d => d -> u) -> Attribute -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Attribute -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Attribute -> m Attribute)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Attribute -> m Attribute)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Attribute -> m Attribute)
-> Data Attribute
Attribute -> Constr
Attribute -> DataType
(forall b. Data b => b -> b) -> Attribute -> Attribute
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Attribute -> u
forall u. (forall d. Data d => d -> u) -> Attribute -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Attribute -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Attribute -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Attribute -> m Attribute
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Attribute -> m Attribute
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Attribute
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Attribute -> c Attribute
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Attribute)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Attribute)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Attribute -> c Attribute
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Attribute -> c Attribute
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Attribute
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Attribute
$ctoConstr :: Attribute -> Constr
toConstr :: Attribute -> Constr
$cdataTypeOf :: Attribute -> DataType
dataTypeOf :: Attribute -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Attribute)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Attribute)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Attribute)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Attribute)
$cgmapT :: (forall b. Data b => b -> b) -> Attribute -> Attribute
gmapT :: (forall b. Data b => b -> b) -> Attribute -> Attribute
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Attribute -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Attribute -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Attribute -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Attribute -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Attribute -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Attribute -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Attribute -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Attribute -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Attribute -> m Attribute
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Attribute -> m Attribute
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Attribute -> m Attribute
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Attribute -> m Attribute
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Attribute -> m Attribute
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Attribute -> m Attribute
Data, (forall x. Attribute -> Rep Attribute x)
-> (forall x. Rep Attribute x -> Attribute) -> Generic Attribute
forall x. Rep Attribute x -> Attribute
forall x. Attribute -> Rep Attribute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Attribute -> Rep Attribute x
from :: forall x. Attribute -> Rep Attribute x
$cto :: forall x. Rep Attribute x -> Attribute
to :: forall x. Rep Attribute x -> Attribute
Generic, (forall (m :: * -> *). Quote m => Attribute -> m Exp)
-> (forall (m :: * -> *). Quote m => Attribute -> Code m Attribute)
-> Lift Attribute
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => Attribute -> m Exp
forall (m :: * -> *). Quote m => Attribute -> Code m Attribute
$clift :: forall (m :: * -> *). Quote m => Attribute -> m Exp
lift :: forall (m :: * -> *). Quote m => Attribute -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => Attribute -> Code m Attribute
liftTyped :: forall (m :: * -> *). Quote m => Attribute -> Code m Attribute
TH.Lift)
  deriving anyclass (Eq Attribute
Eq Attribute =>
(Int -> Attribute -> Int)
-> (Attribute -> Int) -> Hashable Attribute
Int -> Attribute -> Int
Attribute -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> Attribute -> Int
hashWithSalt :: Int -> Attribute -> Int
$chash :: Attribute -> Int
hash :: Attribute -> Int
Hashable)


{- | Create a `TextAttribute` from the string value.

 @since 0.0.2.1
-}
instance IsString PrimitiveAttribute where
  fromString :: String -> PrimitiveAttribute
fromString = Text -> PrimitiveAttribute
TextAttribute (Text -> PrimitiveAttribute)
-> (String -> Text) -> String -> PrimitiveAttribute
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
forall a. IsString a => String -> a
fromString


{- | Create a `TextAttribute` from the string value.

 @since 0.0.2.1
-}
instance IsString Attribute where
  fromString :: String -> Attribute
fromString = PrimitiveAttribute -> Attribute
AttributeValue (PrimitiveAttribute -> Attribute)
-> (String -> PrimitiveAttribute) -> String -> Attribute
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> PrimitiveAttribute
forall a. IsString a => String -> a
fromString


data PrimitiveAttribute
  = TextAttribute Text
  | BoolAttribute Bool
  | DoubleAttribute Double
  | IntAttribute Int64
  deriving stock (ReadPrec [PrimitiveAttribute]
ReadPrec PrimitiveAttribute
Int -> ReadS PrimitiveAttribute
ReadS [PrimitiveAttribute]
(Int -> ReadS PrimitiveAttribute)
-> ReadS [PrimitiveAttribute]
-> ReadPrec PrimitiveAttribute
-> ReadPrec [PrimitiveAttribute]
-> Read PrimitiveAttribute
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS PrimitiveAttribute
readsPrec :: Int -> ReadS PrimitiveAttribute
$creadList :: ReadS [PrimitiveAttribute]
readList :: ReadS [PrimitiveAttribute]
$creadPrec :: ReadPrec PrimitiveAttribute
readPrec :: ReadPrec PrimitiveAttribute
$creadListPrec :: ReadPrec [PrimitiveAttribute]
readListPrec :: ReadPrec [PrimitiveAttribute]
Read, Int -> PrimitiveAttribute -> ShowS
[PrimitiveAttribute] -> ShowS
PrimitiveAttribute -> String
(Int -> PrimitiveAttribute -> ShowS)
-> (PrimitiveAttribute -> String)
-> ([PrimitiveAttribute] -> ShowS)
-> Show PrimitiveAttribute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PrimitiveAttribute -> ShowS
showsPrec :: Int -> PrimitiveAttribute -> ShowS
$cshow :: PrimitiveAttribute -> String
show :: PrimitiveAttribute -> String
$cshowList :: [PrimitiveAttribute] -> ShowS
showList :: [PrimitiveAttribute] -> ShowS
Show, PrimitiveAttribute -> PrimitiveAttribute -> Bool
(PrimitiveAttribute -> PrimitiveAttribute -> Bool)
-> (PrimitiveAttribute -> PrimitiveAttribute -> Bool)
-> Eq PrimitiveAttribute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PrimitiveAttribute -> PrimitiveAttribute -> Bool
== :: PrimitiveAttribute -> PrimitiveAttribute -> Bool
$c/= :: PrimitiveAttribute -> PrimitiveAttribute -> Bool
/= :: PrimitiveAttribute -> PrimitiveAttribute -> Bool
Eq, Eq PrimitiveAttribute
Eq PrimitiveAttribute =>
(PrimitiveAttribute -> PrimitiveAttribute -> Ordering)
-> (PrimitiveAttribute -> PrimitiveAttribute -> Bool)
-> (PrimitiveAttribute -> PrimitiveAttribute -> Bool)
-> (PrimitiveAttribute -> PrimitiveAttribute -> Bool)
-> (PrimitiveAttribute -> PrimitiveAttribute -> Bool)
-> (PrimitiveAttribute -> PrimitiveAttribute -> PrimitiveAttribute)
-> (PrimitiveAttribute -> PrimitiveAttribute -> PrimitiveAttribute)
-> Ord PrimitiveAttribute
PrimitiveAttribute -> PrimitiveAttribute -> Bool
PrimitiveAttribute -> PrimitiveAttribute -> Ordering
PrimitiveAttribute -> PrimitiveAttribute -> PrimitiveAttribute
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PrimitiveAttribute -> PrimitiveAttribute -> Ordering
compare :: PrimitiveAttribute -> PrimitiveAttribute -> Ordering
$c< :: PrimitiveAttribute -> PrimitiveAttribute -> Bool
< :: PrimitiveAttribute -> PrimitiveAttribute -> Bool
$c<= :: PrimitiveAttribute -> PrimitiveAttribute -> Bool
<= :: PrimitiveAttribute -> PrimitiveAttribute -> Bool
$c> :: PrimitiveAttribute -> PrimitiveAttribute -> Bool
> :: PrimitiveAttribute -> PrimitiveAttribute -> Bool
$c>= :: PrimitiveAttribute -> PrimitiveAttribute -> Bool
>= :: PrimitiveAttribute -> PrimitiveAttribute -> Bool
$cmax :: PrimitiveAttribute -> PrimitiveAttribute -> PrimitiveAttribute
max :: PrimitiveAttribute -> PrimitiveAttribute -> PrimitiveAttribute
$cmin :: PrimitiveAttribute -> PrimitiveAttribute -> PrimitiveAttribute
min :: PrimitiveAttribute -> PrimitiveAttribute -> PrimitiveAttribute
Ord, Typeable PrimitiveAttribute
Typeable PrimitiveAttribute =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g)
 -> PrimitiveAttribute
 -> c PrimitiveAttribute)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PrimitiveAttribute)
-> (PrimitiveAttribute -> Constr)
-> (PrimitiveAttribute -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PrimitiveAttribute))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c PrimitiveAttribute))
-> ((forall b. Data b => b -> b)
    -> PrimitiveAttribute -> PrimitiveAttribute)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PrimitiveAttribute -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PrimitiveAttribute -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> PrimitiveAttribute -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> PrimitiveAttribute -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> PrimitiveAttribute -> m PrimitiveAttribute)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> PrimitiveAttribute -> m PrimitiveAttribute)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> PrimitiveAttribute -> m PrimitiveAttribute)
-> Data PrimitiveAttribute
PrimitiveAttribute -> Constr
PrimitiveAttribute -> DataType
(forall b. Data b => b -> b)
-> PrimitiveAttribute -> PrimitiveAttribute
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> PrimitiveAttribute -> u
forall u. (forall d. Data d => d -> u) -> PrimitiveAttribute -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PrimitiveAttribute -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PrimitiveAttribute -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> PrimitiveAttribute -> m PrimitiveAttribute
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PrimitiveAttribute -> m PrimitiveAttribute
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PrimitiveAttribute
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PrimitiveAttribute
-> c PrimitiveAttribute
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PrimitiveAttribute)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PrimitiveAttribute)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PrimitiveAttribute
-> c PrimitiveAttribute
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PrimitiveAttribute
-> c PrimitiveAttribute
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PrimitiveAttribute
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PrimitiveAttribute
$ctoConstr :: PrimitiveAttribute -> Constr
toConstr :: PrimitiveAttribute -> Constr
$cdataTypeOf :: PrimitiveAttribute -> DataType
dataTypeOf :: PrimitiveAttribute -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PrimitiveAttribute)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PrimitiveAttribute)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PrimitiveAttribute)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PrimitiveAttribute)
$cgmapT :: (forall b. Data b => b -> b)
-> PrimitiveAttribute -> PrimitiveAttribute
gmapT :: (forall b. Data b => b -> b)
-> PrimitiveAttribute -> PrimitiveAttribute
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PrimitiveAttribute -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PrimitiveAttribute -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PrimitiveAttribute -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PrimitiveAttribute -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PrimitiveAttribute -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PrimitiveAttribute -> [u]
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> PrimitiveAttribute -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> PrimitiveAttribute -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> PrimitiveAttribute -> m PrimitiveAttribute
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> PrimitiveAttribute -> m PrimitiveAttribute
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PrimitiveAttribute -> m PrimitiveAttribute
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PrimitiveAttribute -> m PrimitiveAttribute
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PrimitiveAttribute -> m PrimitiveAttribute
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PrimitiveAttribute -> m PrimitiveAttribute
Data, (forall x. PrimitiveAttribute -> Rep PrimitiveAttribute x)
-> (forall x. Rep PrimitiveAttribute x -> PrimitiveAttribute)
-> Generic PrimitiveAttribute
forall x. Rep PrimitiveAttribute x -> PrimitiveAttribute
forall x. PrimitiveAttribute -> Rep PrimitiveAttribute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PrimitiveAttribute -> Rep PrimitiveAttribute x
from :: forall x. PrimitiveAttribute -> Rep PrimitiveAttribute x
$cto :: forall x. Rep PrimitiveAttribute x -> PrimitiveAttribute
to :: forall x. Rep PrimitiveAttribute x -> PrimitiveAttribute
Generic, (forall (m :: * -> *). Quote m => PrimitiveAttribute -> m Exp)
-> (forall (m :: * -> *).
    Quote m =>
    PrimitiveAttribute -> Code m PrimitiveAttribute)
-> Lift PrimitiveAttribute
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => PrimitiveAttribute -> m Exp
forall (m :: * -> *).
Quote m =>
PrimitiveAttribute -> Code m PrimitiveAttribute
$clift :: forall (m :: * -> *). Quote m => PrimitiveAttribute -> m Exp
lift :: forall (m :: * -> *). Quote m => PrimitiveAttribute -> m Exp
$cliftTyped :: forall (m :: * -> *).
Quote m =>
PrimitiveAttribute -> Code m PrimitiveAttribute
liftTyped :: forall (m :: * -> *).
Quote m =>
PrimitiveAttribute -> Code m PrimitiveAttribute
TH.Lift)
  deriving anyclass (Eq PrimitiveAttribute
Eq PrimitiveAttribute =>
(Int -> PrimitiveAttribute -> Int)
-> (PrimitiveAttribute -> Int) -> Hashable PrimitiveAttribute
Int -> PrimitiveAttribute -> Int
PrimitiveAttribute -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> PrimitiveAttribute -> Int
hashWithSalt :: Int -> PrimitiveAttribute -> Int
$chash :: PrimitiveAttribute -> Int
hash :: PrimitiveAttribute -> Int
Hashable)


{- | Convert a Haskell value to an 'Attribute' value.

 For most values, you can define an instance of 'ToPrimitiveAttribute' and use the default 'toAttribute' implementation:

 @

 data Foo = Foo

 instance ToPrimitiveAttribute Foo where
   toPrimitiveAttribute Foo = TextAttribute "Foo"
 instance ToAttribute foo

 @
-}
class ToAttribute a where
  toAttribute :: a -> Attribute
  default toAttribute :: (ToPrimitiveAttribute a) => a -> Attribute
  toAttribute = PrimitiveAttribute -> Attribute
AttributeValue (PrimitiveAttribute -> Attribute)
-> (a -> PrimitiveAttribute) -> a -> Attribute
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> PrimitiveAttribute
forall a. ToPrimitiveAttribute a => a -> PrimitiveAttribute
toPrimitiveAttribute


class FromAttribute a where
  fromAttribute :: Attribute -> Maybe a
  default fromAttribute :: (FromPrimitiveAttribute a) => Attribute -> Maybe a
  fromAttribute (AttributeValue PrimitiveAttribute
v) = PrimitiveAttribute -> Maybe a
forall a. FromPrimitiveAttribute a => PrimitiveAttribute -> Maybe a
fromPrimitiveAttribute PrimitiveAttribute
v
  fromAttribute Attribute
_ = Maybe a
forall a. Maybe a
Nothing


instance ToPrimitiveAttribute PrimitiveAttribute where
  toPrimitiveAttribute :: PrimitiveAttribute -> PrimitiveAttribute
toPrimitiveAttribute = PrimitiveAttribute -> PrimitiveAttribute
forall a. a -> a
id


instance FromPrimitiveAttribute PrimitiveAttribute where
  fromPrimitiveAttribute :: PrimitiveAttribute -> Maybe PrimitiveAttribute
fromPrimitiveAttribute = PrimitiveAttribute -> Maybe PrimitiveAttribute
forall a. a -> Maybe a
Just


instance ToAttribute PrimitiveAttribute where
  toAttribute :: PrimitiveAttribute -> Attribute
toAttribute = PrimitiveAttribute -> Attribute
AttributeValue


instance FromAttribute PrimitiveAttribute where
  fromAttribute :: Attribute -> Maybe PrimitiveAttribute
fromAttribute (AttributeValue PrimitiveAttribute
v) = PrimitiveAttribute -> Maybe PrimitiveAttribute
forall a. a -> Maybe a
Just PrimitiveAttribute
v
  fromAttribute Attribute
_ = Maybe PrimitiveAttribute
forall a. Maybe a
Nothing


instance ToPrimitiveAttribute Text where
  toPrimitiveAttribute :: Text -> PrimitiveAttribute
toPrimitiveAttribute = Text -> PrimitiveAttribute
TextAttribute


instance FromPrimitiveAttribute Text where
  fromPrimitiveAttribute :: PrimitiveAttribute -> Maybe Text
fromPrimitiveAttribute (TextAttribute Text
v) = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
v
  fromPrimitiveAttribute PrimitiveAttribute
_ = Maybe Text
forall a. Maybe a
Nothing


instance ToAttribute Text


instance FromAttribute Text


instance ToPrimitiveAttribute Bool where
  toPrimitiveAttribute :: Bool -> PrimitiveAttribute
toPrimitiveAttribute = Bool -> PrimitiveAttribute
BoolAttribute


instance FromPrimitiveAttribute Bool where
  fromPrimitiveAttribute :: PrimitiveAttribute -> Maybe Bool
fromPrimitiveAttribute (BoolAttribute Bool
v) = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
v
  fromPrimitiveAttribute PrimitiveAttribute
_ = Maybe Bool
forall a. Maybe a
Nothing


instance ToAttribute Bool


instance FromAttribute Bool


instance ToPrimitiveAttribute Double where
  toPrimitiveAttribute :: Double -> PrimitiveAttribute
toPrimitiveAttribute = Double -> PrimitiveAttribute
DoubleAttribute


instance FromPrimitiveAttribute Double where
  fromPrimitiveAttribute :: PrimitiveAttribute -> Maybe Double
fromPrimitiveAttribute (DoubleAttribute Double
v) = Double -> Maybe Double
forall a. a -> Maybe a
Just Double
v
  fromPrimitiveAttribute PrimitiveAttribute
_ = Maybe Double
forall a. Maybe a
Nothing


instance ToAttribute Double


instance FromAttribute Double


instance ToPrimitiveAttribute Int64 where
  toPrimitiveAttribute :: Int64 -> PrimitiveAttribute
toPrimitiveAttribute = Int64 -> PrimitiveAttribute
IntAttribute


instance FromPrimitiveAttribute Int64 where
  fromPrimitiveAttribute :: PrimitiveAttribute -> Maybe Int64
fromPrimitiveAttribute (IntAttribute Int64
v) = Int64 -> Maybe Int64
forall a. a -> Maybe a
Just Int64
v
  fromPrimitiveAttribute PrimitiveAttribute
_ = Maybe Int64
forall a. Maybe a
Nothing


instance ToAttribute Int64


instance FromAttribute Int64


instance ToPrimitiveAttribute Int where
  toPrimitiveAttribute :: Int -> PrimitiveAttribute
toPrimitiveAttribute = Int64 -> PrimitiveAttribute
IntAttribute (Int64 -> PrimitiveAttribute)
-> (Int -> Int64) -> Int -> PrimitiveAttribute
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral


instance FromPrimitiveAttribute Int where
  fromPrimitiveAttribute :: PrimitiveAttribute -> Maybe Int
fromPrimitiveAttribute (IntAttribute Int64
v) = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> Int -> Maybe Int
forall a b. (a -> b) -> a -> b
$ Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
v
  fromPrimitiveAttribute PrimitiveAttribute
_ = Maybe Int
forall a. Maybe a
Nothing


instance ToAttribute Int


instance FromAttribute Int


instance ToAttribute Attribute where
  toAttribute :: Attribute -> Attribute
toAttribute = Attribute -> Attribute
forall a. a -> a
id


instance FromAttribute Attribute where
  fromAttribute :: Attribute -> Maybe Attribute
fromAttribute = Attribute -> Maybe Attribute
forall a. a -> Maybe a
Just


instance (ToPrimitiveAttribute a) => ToAttribute [a] where
  toAttribute :: [a] -> Attribute
toAttribute = [PrimitiveAttribute] -> Attribute
AttributeArray ([PrimitiveAttribute] -> Attribute)
-> ([a] -> [PrimitiveAttribute]) -> [a] -> Attribute
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> PrimitiveAttribute) -> [a] -> [PrimitiveAttribute]
forall a b. (a -> b) -> [a] -> [b]
L.map a -> PrimitiveAttribute
forall a. ToPrimitiveAttribute a => a -> PrimitiveAttribute
toPrimitiveAttribute


instance (FromPrimitiveAttribute a) => FromAttribute [a] where
  fromAttribute :: Attribute -> Maybe [a]
fromAttribute (AttributeArray [PrimitiveAttribute]
arr) = (PrimitiveAttribute -> Maybe a)
-> [PrimitiveAttribute] -> Maybe [a]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse PrimitiveAttribute -> Maybe a
forall a. FromPrimitiveAttribute a => PrimitiveAttribute -> Maybe a
fromPrimitiveAttribute [PrimitiveAttribute]
arr
  fromAttribute Attribute
_ = Maybe [a]
forall a. Maybe a
Nothing