{-|
Module      : Gargantext.Database.Admin.Types.Hyperdata.Any
Description :
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

-}

{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE NoImplicitPrelude          #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE RankNTypes                 #-}
{-# LANGUAGE TemplateHaskell            #-}

module Gargantext.Database.Admin.Types.Hyperdata.Any
  where

import Gargantext.Prelude
import Gargantext.Database.Admin.Types.Hyperdata.Prelude

------------------------------------------------------------------------
newtype HyperdataAny = HyperdataAny Object
  deriving (Int -> HyperdataAny -> ShowS
[HyperdataAny] -> ShowS
HyperdataAny -> String
(Int -> HyperdataAny -> ShowS)
-> (HyperdataAny -> String)
-> ([HyperdataAny] -> ShowS)
-> Show HyperdataAny
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HyperdataAny] -> ShowS
$cshowList :: [HyperdataAny] -> ShowS
show :: HyperdataAny -> String
$cshow :: HyperdataAny -> String
showsPrec :: Int -> HyperdataAny -> ShowS
$cshowsPrec :: Int -> HyperdataAny -> ShowS
Show, (forall x. HyperdataAny -> Rep HyperdataAny x)
-> (forall x. Rep HyperdataAny x -> HyperdataAny)
-> Generic HyperdataAny
forall x. Rep HyperdataAny x -> HyperdataAny
forall x. HyperdataAny -> Rep HyperdataAny x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HyperdataAny x -> HyperdataAny
$cfrom :: forall x. HyperdataAny -> Rep HyperdataAny x
Generic, [HyperdataAny] -> Encoding
[HyperdataAny] -> Value
HyperdataAny -> Encoding
HyperdataAny -> Value
(HyperdataAny -> Value)
-> (HyperdataAny -> Encoding)
-> ([HyperdataAny] -> Value)
-> ([HyperdataAny] -> Encoding)
-> ToJSON HyperdataAny
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [HyperdataAny] -> Encoding
$ctoEncodingList :: [HyperdataAny] -> Encoding
toJSONList :: [HyperdataAny] -> Value
$ctoJSONList :: [HyperdataAny] -> Value
toEncoding :: HyperdataAny -> Encoding
$ctoEncoding :: HyperdataAny -> Encoding
toJSON :: HyperdataAny -> Value
$ctoJSON :: HyperdataAny -> Value
ToJSON, Value -> Parser [HyperdataAny]
Value -> Parser HyperdataAny
(Value -> Parser HyperdataAny)
-> (Value -> Parser [HyperdataAny]) -> FromJSON HyperdataAny
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [HyperdataAny]
$cparseJSONList :: Value -> Parser [HyperdataAny]
parseJSON :: Value -> Parser HyperdataAny
$cparseJSON :: Value -> Parser HyperdataAny
FromJSON)

------------------------------------------------------------------------
-- Instances
------------------------------------------------------------------------
instance Hyperdata HyperdataAny

instance Arbitrary HyperdataAny where
    arbitrary :: Gen HyperdataAny
arbitrary = HyperdataAny -> Gen HyperdataAny
forall (f :: * -> *) a. Applicative f => a -> f a
pure (HyperdataAny -> Gen HyperdataAny)
-> HyperdataAny -> Gen HyperdataAny
forall a b. (a -> b) -> a -> b
$ Object -> HyperdataAny
HyperdataAny Object
forall a. Monoid a => a
mempty -- TODO produce arbitrary objects

instance ToSchema HyperdataAny where
  declareNamedSchema :: Proxy HyperdataAny -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy HyperdataAny
proxy =
    NamedSchema -> Declare (Definitions Schema) NamedSchema
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NamedSchema -> Declare (Definitions Schema) NamedSchema)
-> NamedSchema -> Declare (Definitions Schema) NamedSchema
forall a b. (a -> b) -> a -> b
$ SchemaOptions -> Proxy HyperdataAny -> Schema -> NamedSchema
forall a (d :: Meta) (f :: * -> *).
(Generic a, Rep a ~ D1 d f, Datatype d) =>
SchemaOptions -> Proxy a -> Schema -> NamedSchema
genericNameSchema SchemaOptions
defaultSchemaOptions Proxy HyperdataAny
proxy Schema
forall a. Monoid a => a
mempty
         NamedSchema -> (NamedSchema -> NamedSchema) -> NamedSchema
forall a b. a -> (a -> b) -> b
& (Schema -> Identity Schema) -> NamedSchema -> Identity NamedSchema
forall s a. HasSchema s a => Lens' s a
schema((Schema -> Identity Schema)
 -> NamedSchema -> Identity NamedSchema)
-> ((Maybe Text -> Identity (Maybe Text))
    -> Schema -> Identity Schema)
-> (Maybe Text -> Identity (Maybe Text))
-> NamedSchema
-> Identity NamedSchema
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe Text -> Identity (Maybe Text)) -> Schema -> Identity Schema
forall s a. HasDescription s a => Lens' s a
description ((Maybe Text -> Identity (Maybe Text))
 -> NamedSchema -> Identity NamedSchema)
-> Text -> NamedSchema -> NamedSchema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text
"Hyperdata of any node (Json Value)"
         NamedSchema -> (NamedSchema -> NamedSchema) -> NamedSchema
forall a b. a -> (a -> b) -> b
& (Schema -> Identity Schema) -> NamedSchema -> Identity NamedSchema
forall s a. HasSchema s a => Lens' s a
schema((Schema -> Identity Schema)
 -> NamedSchema -> Identity NamedSchema)
-> ((Maybe Value -> Identity (Maybe Value))
    -> Schema -> Identity Schema)
-> (Maybe Value -> Identity (Maybe Value))
-> NamedSchema
-> Identity NamedSchema
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe Value -> Identity (Maybe Value))
-> Schema -> Identity Schema
forall s a. HasExample s a => Lens' s a
example ((Maybe Value -> Identity (Maybe Value))
 -> NamedSchema -> Identity NamedSchema)
-> Value -> NamedSchema -> NamedSchema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Value
emptyObject -- TODO

instance FromField HyperdataAny where
    fromField :: FieldParser HyperdataAny
fromField = FieldParser HyperdataAny
forall b.
(Typeable b, FromJSON b) =>
Field -> Maybe ByteString -> Conversion b
fromField'

instance DefaultFromField PGJsonb HyperdataAny
  where
    defaultFromField :: FromField PGJsonb HyperdataAny
defaultFromField = FromField PGJsonb HyperdataAny
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn