{-|
Module      : Gargantext.Database.Admin.Types.Hyperdata.Phylo
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.Phylo
  where

import Gargantext.Prelude
import Gargantext.Database.Admin.Types.Hyperdata.Prelude
import Gargantext.Core.Viz.LegacyPhylo (Phylo(..))

------------------------------------------------------------------------

data HyperdataPhylo =
  HyperdataPhylo    { HyperdataPhylo -> Maybe Text
_hp_preferences :: !(Maybe Text)
                    , HyperdataPhylo -> Maybe Phylo
_hp_data        :: !(Maybe Phylo)
                    }
  deriving (Int -> HyperdataPhylo -> ShowS
[HyperdataPhylo] -> ShowS
HyperdataPhylo -> String
(Int -> HyperdataPhylo -> ShowS)
-> (HyperdataPhylo -> String)
-> ([HyperdataPhylo] -> ShowS)
-> Show HyperdataPhylo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HyperdataPhylo] -> ShowS
$cshowList :: [HyperdataPhylo] -> ShowS
show :: HyperdataPhylo -> String
$cshow :: HyperdataPhylo -> String
showsPrec :: Int -> HyperdataPhylo -> ShowS
$cshowsPrec :: Int -> HyperdataPhylo -> ShowS
Show, (forall x. HyperdataPhylo -> Rep HyperdataPhylo x)
-> (forall x. Rep HyperdataPhylo x -> HyperdataPhylo)
-> Generic HyperdataPhylo
forall x. Rep HyperdataPhylo x -> HyperdataPhylo
forall x. HyperdataPhylo -> Rep HyperdataPhylo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HyperdataPhylo x -> HyperdataPhylo
$cfrom :: forall x. HyperdataPhylo -> Rep HyperdataPhylo x
Generic)

defaultHyperdataPhylo :: HyperdataPhylo
defaultHyperdataPhylo :: HyperdataPhylo
defaultHyperdataPhylo = Maybe Text -> Maybe Phylo -> HyperdataPhylo
HyperdataPhylo Maybe Text
forall a. Maybe a
Nothing Maybe Phylo
forall a. Maybe a
Nothing

------------------------------------------------------------------------
-- Instances
------------------------------------------------------------------------
instance Hyperdata HyperdataPhylo

$(makeLenses ''HyperdataPhylo)
$(deriveJSON (unPrefix "_hp_") ''HyperdataPhylo)

instance Arbitrary HyperdataPhylo where
    arbitrary :: Gen HyperdataPhylo
arbitrary = HyperdataPhylo -> Gen HyperdataPhylo
forall (f :: * -> *) a. Applicative f => a -> f a
pure HyperdataPhylo
defaultHyperdataPhylo

instance ToSchema HyperdataPhylo where
  declareNamedSchema :: Proxy HyperdataPhylo -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy HyperdataPhylo
proxy =
    SchemaOptions
-> Proxy HyperdataPhylo -> Declare (Definitions Schema) NamedSchema
forall a.
(Generic a, GToSchema (Rep a),
 TypeHasSimpleShape a "genericDeclareNamedSchemaUnrestricted") =>
SchemaOptions
-> Proxy a -> Declare (Definitions Schema) NamedSchema
genericDeclareNamedSchema (String -> SchemaOptions
unPrefixSwagger String
"_hp_") Proxy HyperdataPhylo
proxy
    Declare (Definitions Schema) NamedSchema
-> (Declare (Definitions Schema) NamedSchema
    -> Declare (Definitions Schema) NamedSchema)
-> Declare (Definitions Schema) NamedSchema
forall a b. a -> (a -> b) -> b
& (NamedSchema -> Identity NamedSchema)
-> Declare (Definitions Schema) NamedSchema
-> Identity (Declare (Definitions Schema) NamedSchema)
forall (f :: * -> *) a b. Functor f => Setter (f a) (f b) a b
mapped((NamedSchema -> Identity NamedSchema)
 -> Declare (Definitions Schema) NamedSchema
 -> Identity (Declare (Definitions Schema) NamedSchema))
-> ((Maybe Text -> Identity (Maybe Text))
    -> NamedSchema -> Identity NamedSchema)
-> (Maybe Text -> Identity (Maybe Text))
-> Declare (Definitions Schema) NamedSchema
-> Identity (Declare (Definitions Schema) NamedSchema)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(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))
 -> Declare (Definitions Schema) NamedSchema
 -> Identity (Declare (Definitions Schema) NamedSchema))
-> Text
-> Declare (Definitions Schema) NamedSchema
-> Declare (Definitions Schema) NamedSchema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text
"Phylo Hyperdata"
    Declare (Definitions Schema) NamedSchema
-> (Declare (Definitions Schema) NamedSchema
    -> Declare (Definitions Schema) NamedSchema)
-> Declare (Definitions Schema) NamedSchema
forall a b. a -> (a -> b) -> b
& (NamedSchema -> Identity NamedSchema)
-> Declare (Definitions Schema) NamedSchema
-> Identity (Declare (Definitions Schema) NamedSchema)
forall (f :: * -> *) a b. Functor f => Setter (f a) (f b) a b
mapped((NamedSchema -> Identity NamedSchema)
 -> Declare (Definitions Schema) NamedSchema
 -> Identity (Declare (Definitions Schema) NamedSchema))
-> ((Maybe Value -> Identity (Maybe Value))
    -> NamedSchema -> Identity NamedSchema)
-> (Maybe Value -> Identity (Maybe Value))
-> Declare (Definitions Schema) NamedSchema
-> Identity (Declare (Definitions Schema) NamedSchema)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(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))
 -> Declare (Definitions Schema) NamedSchema
 -> Identity (Declare (Definitions Schema) NamedSchema))
-> Value
-> Declare (Definitions Schema) NamedSchema
-> Declare (Definitions Schema) NamedSchema
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ HyperdataPhylo -> Value
forall a. ToJSON a => a -> Value
toJSON HyperdataPhylo
defaultHyperdataPhylo

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

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