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

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

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

data HyperdataDashboard =
  HyperdataDashboard { HyperdataDashboard -> Maybe Text
_hd_preferences :: !(Maybe Text)
                     , HyperdataDashboard -> [Chart]
_hd_charts      :: ![Chart]
                     , HyperdataDashboard -> [HyperdataField CorpusField]
_hd_fields      :: ![HyperdataField CorpusField]
                     }
  deriving (Int -> HyperdataDashboard -> ShowS
[HyperdataDashboard] -> ShowS
HyperdataDashboard -> String
(Int -> HyperdataDashboard -> ShowS)
-> (HyperdataDashboard -> String)
-> ([HyperdataDashboard] -> ShowS)
-> Show HyperdataDashboard
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HyperdataDashboard] -> ShowS
$cshowList :: [HyperdataDashboard] -> ShowS
show :: HyperdataDashboard -> String
$cshow :: HyperdataDashboard -> String
showsPrec :: Int -> HyperdataDashboard -> ShowS
$cshowsPrec :: Int -> HyperdataDashboard -> ShowS
Show, (forall x. HyperdataDashboard -> Rep HyperdataDashboard x)
-> (forall x. Rep HyperdataDashboard x -> HyperdataDashboard)
-> Generic HyperdataDashboard
forall x. Rep HyperdataDashboard x -> HyperdataDashboard
forall x. HyperdataDashboard -> Rep HyperdataDashboard x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HyperdataDashboard x -> HyperdataDashboard
$cfrom :: forall x. HyperdataDashboard -> Rep HyperdataDashboard x
Generic)


defaultHyperdataDashboard :: HyperdataDashboard
defaultHyperdataDashboard :: HyperdataDashboard
defaultHyperdataDashboard = Maybe Text
-> [Chart] -> [HyperdataField CorpusField] -> HyperdataDashboard
HyperdataDashboard Maybe Text
forall a. Maybe a
Nothing [] [HyperdataField CorpusField]
defaultHyperdataDashboardFields

defaultHyperdataDashboardFields :: [HyperdataField CorpusField]
defaultHyperdataDashboardFields :: [HyperdataField CorpusField]
defaultHyperdataDashboardFields =
  [ CodeType -> Text -> CorpusField -> HyperdataField CorpusField
forall a. CodeType -> Text -> a -> HyperdataField a
HyperdataField CodeType
Markdown
                   Text
"DashBoard Title"
                   (Text -> CorpusField
MarkdownField Text
"# DashBoard Title\n## Dashboard subtitle\nText and Chart cells.")

  {- , HyperdataField JSON
                  "Metadata (Experts only)"
                  (JsonField "Title" "Descr" "Bool query" "Authors")
  -}
  ]

------------------------------------------------------------------------
-- Instances
------------------------------------------------------------------------
instance Hyperdata HyperdataDashboard

$(makeLenses ''HyperdataDashboard)
$(deriveJSON (unPrefix "_hd_") ''HyperdataDashboard)

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

instance ToSchema HyperdataDashboard where
  declareNamedSchema :: Proxy HyperdataDashboard
-> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy HyperdataDashboard
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 HyperdataDashboard -> 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 HyperdataDashboard
proxy Schema
forall a. Monoid a => a
mempty
    -- genericDeclareNamedSchema (unPrefixSwagger "hp_") proxy
             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
"Dashboard Hyperdata"
             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
?~ HyperdataDashboard -> Value
forall a. ToJSON a => a -> Value
toJSON HyperdataDashboard
defaultHyperdataDashboard

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

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