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

import Data.Vector (Vector)
--import qualified Data.Vector as V
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HM
import Control.Applicative

import Gargantext.Prelude
import Gargantext.Core.Viz.Types (Histo(..))
import Gargantext.API.Ngrams.NgramsTree (NgramsTree)
import Gargantext.API.Ngrams.Types (TabType)
import Gargantext.Database.Admin.Types.Hyperdata.Prelude
import Gargantext.Database.Admin.Types.Metrics (ChartMetrics(..), Metrics)

------------------------------------------------------------------------
data HyperdataList =
  HyperdataList { HyperdataList -> HashMap TabType (ChartMetrics Histo)
_hl_chart   :: !(HashMap TabType (ChartMetrics Histo))
                , HyperdataList -> Maybe Text
_hl_list    :: !(Maybe Text)
                , HyperdataList -> HashMap TabType (ChartMetrics Histo)
_hl_pie     :: !(HashMap TabType (ChartMetrics Histo))
                , HyperdataList -> HashMap TabType Metrics
_hl_scatter :: !(HashMap TabType Metrics)
                , HyperdataList -> HashMap TabType (ChartMetrics (Vector NgramsTree))
_hl_tree    :: !(HashMap TabType (ChartMetrics (Vector NgramsTree)))
                } deriving (Int -> HyperdataList -> ShowS
[HyperdataList] -> ShowS
HyperdataList -> String
(Int -> HyperdataList -> ShowS)
-> (HyperdataList -> String)
-> ([HyperdataList] -> ShowS)
-> Show HyperdataList
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HyperdataList] -> ShowS
$cshowList :: [HyperdataList] -> ShowS
show :: HyperdataList -> String
$cshow :: HyperdataList -> String
showsPrec :: Int -> HyperdataList -> ShowS
$cshowsPrec :: Int -> HyperdataList -> ShowS
Show, (forall x. HyperdataList -> Rep HyperdataList x)
-> (forall x. Rep HyperdataList x -> HyperdataList)
-> Generic HyperdataList
forall x. Rep HyperdataList x -> HyperdataList
forall x. HyperdataList -> Rep HyperdataList x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HyperdataList x -> HyperdataList
$cfrom :: forall x. HyperdataList -> Rep HyperdataList x
Generic)
  -- HyperdataList { _hl_chart   :: !(Maybe (ChartMetrics Histo))
  --               , _hl_list    :: !(Maybe Text)
  --               , _hl_pie     :: !(Maybe (ChartMetrics Histo))
  --               , _hl_scatter :: !(Maybe Metrics)
  --               , _hl_tree    :: !(Maybe (ChartMetrics [NgramsTree]))
  --               } deriving (Show, Generic)

defaultHyperdataList :: HyperdataList
defaultHyperdataList :: HyperdataList
defaultHyperdataList =
  HyperdataList :: HashMap TabType (ChartMetrics Histo)
-> Maybe Text
-> HashMap TabType (ChartMetrics Histo)
-> HashMap TabType Metrics
-> HashMap TabType (ChartMetrics (Vector NgramsTree))
-> HyperdataList
HyperdataList { _hl_chart :: HashMap TabType (ChartMetrics Histo)
_hl_chart   = HashMap TabType (ChartMetrics Histo)
forall k v. HashMap k v
HM.empty
                , _hl_list :: Maybe Text
_hl_list    = Maybe Text
forall a. Maybe a
Nothing
                , _hl_pie :: HashMap TabType (ChartMetrics Histo)
_hl_pie     = HashMap TabType (ChartMetrics Histo)
forall k v. HashMap k v
HM.empty
                , _hl_scatter :: HashMap TabType Metrics
_hl_scatter = HashMap TabType Metrics
forall k v. HashMap k v
HM.empty
                , _hl_tree :: HashMap TabType (ChartMetrics (Vector NgramsTree))
_hl_tree    = HashMap TabType (ChartMetrics (Vector NgramsTree))
forall k v. HashMap k v
HM.empty
                }

------------------------------------------------------------------------
-- Instances
------------------------------------------------------------------------
instance Hyperdata HyperdataList

$(makeLenses ''HyperdataList)
$(deriveJSON (unPrefix "_hl_") ''HyperdataList)


------------------------------------------------------------------------
data HyperdataListCooc =
  HyperdataListCooc { HyperdataListCooc -> Text
_hlc_preferences :: !Text }
  deriving ((forall x. HyperdataListCooc -> Rep HyperdataListCooc x)
-> (forall x. Rep HyperdataListCooc x -> HyperdataListCooc)
-> Generic HyperdataListCooc
forall x. Rep HyperdataListCooc x -> HyperdataListCooc
forall x. HyperdataListCooc -> Rep HyperdataListCooc x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HyperdataListCooc x -> HyperdataListCooc
$cfrom :: forall x. HyperdataListCooc -> Rep HyperdataListCooc x
Generic)

defaultHyperdataListCooc :: HyperdataListCooc
defaultHyperdataListCooc :: HyperdataListCooc
defaultHyperdataListCooc = Text -> HyperdataListCooc
HyperdataListCooc Text
""


instance Hyperdata HyperdataListCooc
$(makeLenses ''HyperdataListCooc)
$(deriveJSON (unPrefix "_hlc_") ''HyperdataListCooc)





instance Arbitrary HyperdataList where
  arbitrary :: Gen HyperdataList
arbitrary = HyperdataList -> Gen HyperdataList
forall (f :: * -> *) a. Applicative f => a -> f a
pure HyperdataList
defaultHyperdataList
instance Arbitrary HyperdataListCooc where
  arbitrary :: Gen HyperdataListCooc
arbitrary = HyperdataListCooc -> Gen HyperdataListCooc
forall (f :: * -> *) a. Applicative f => a -> f a
pure HyperdataListCooc
defaultHyperdataListCooc


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

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

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


instance ToSchema HyperdataList where
  declareNamedSchema :: Proxy HyperdataList -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy HyperdataList
proxy =
    SchemaOptions
-> Proxy HyperdataList -> 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
"_hl_") Proxy HyperdataList
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
"List 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
?~ HyperdataList -> Value
forall a. ToJSON a => a -> Value
toJSON HyperdataList
defaultHyperdataList
instance ToSchema HyperdataListCooc where
  declareNamedSchema :: Proxy HyperdataListCooc -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy HyperdataListCooc
proxy =
    SchemaOptions
-> Proxy HyperdataListCooc
-> 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
"_hlc_") Proxy HyperdataListCooc
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
"List Cooc 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
?~ HyperdataListCooc -> Value
forall a. ToJSON a => a -> Value
toJSON HyperdataListCooc
defaultHyperdataListCooc