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

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

------------------------------------------------------------------------
data HyperdataCorpus =
  HyperdataCorpus { HyperdataCorpus -> [HyperdataField CorpusField]
_hc_fields :: ![HyperdataField CorpusField] }
    deriving ((forall x. HyperdataCorpus -> Rep HyperdataCorpus x)
-> (forall x. Rep HyperdataCorpus x -> HyperdataCorpus)
-> Generic HyperdataCorpus
forall x. Rep HyperdataCorpus x -> HyperdataCorpus
forall x. HyperdataCorpus -> Rep HyperdataCorpus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HyperdataCorpus x -> HyperdataCorpus
$cfrom :: forall x. HyperdataCorpus -> Rep HyperdataCorpus x
Generic)

defaultHyperdataCorpus :: HyperdataCorpus
defaultHyperdataCorpus :: HyperdataCorpus
defaultHyperdataCorpus =
  [HyperdataField CorpusField] -> HyperdataCorpus
HyperdataCorpus [ CodeType -> Text -> CorpusField -> HyperdataField CorpusField
forall a. CodeType -> Text -> a -> HyperdataField a
HyperdataField CodeType
Markdown
                                   Text
"Corpus analysis"
                                   (Text -> CorpusField
MarkdownField Text
"# title\n## subtitle")

                  , CodeType -> Text -> CorpusField -> HyperdataField CorpusField
forall a. CodeType -> Text -> a -> HyperdataField a
HyperdataField CodeType
JSON
                                   Text
"Metadata (Experts only)"
                                   (Text -> Text -> Text -> Text -> CorpusField
JsonField Text
"Title" Text
"Descr" Text
"Bool query" Text
"Authors")
                  ]

------------------------------------------------------------------------
------------------------------------------------------------------------
-- | Annuaire and Corpus should be the same
data HyperdataAnnuaire = HyperdataAnnuaire { HyperdataAnnuaire -> Maybe Text
_ha_title        :: !(Maybe Text)
                                           , HyperdataAnnuaire -> Maybe Text
_ha_desc         :: !(Maybe Text)
                                           } deriving (Int -> HyperdataAnnuaire -> ShowS
[HyperdataAnnuaire] -> ShowS
HyperdataAnnuaire -> String
(Int -> HyperdataAnnuaire -> ShowS)
-> (HyperdataAnnuaire -> String)
-> ([HyperdataAnnuaire] -> ShowS)
-> Show HyperdataAnnuaire
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HyperdataAnnuaire] -> ShowS
$cshowList :: [HyperdataAnnuaire] -> ShowS
show :: HyperdataAnnuaire -> String
$cshow :: HyperdataAnnuaire -> String
showsPrec :: Int -> HyperdataAnnuaire -> ShowS
$cshowsPrec :: Int -> HyperdataAnnuaire -> ShowS
Show, (forall x. HyperdataAnnuaire -> Rep HyperdataAnnuaire x)
-> (forall x. Rep HyperdataAnnuaire x -> HyperdataAnnuaire)
-> Generic HyperdataAnnuaire
forall x. Rep HyperdataAnnuaire x -> HyperdataAnnuaire
forall x. HyperdataAnnuaire -> Rep HyperdataAnnuaire x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HyperdataAnnuaire x -> HyperdataAnnuaire
$cfrom :: forall x. HyperdataAnnuaire -> Rep HyperdataAnnuaire x
Generic)

defaultHyperdataAnnuaire :: HyperdataAnnuaire
defaultHyperdataAnnuaire :: HyperdataAnnuaire
defaultHyperdataAnnuaire = Maybe Text -> Maybe Text -> HyperdataAnnuaire
HyperdataAnnuaire (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"Title") (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"Description")

------------------------------------------------------------------------
-- Instances
------------------------------------------------------------------------
instance Hyperdata HyperdataCorpus
instance Hyperdata HyperdataAnnuaire

$(makeLenses ''HyperdataCorpus)
$(makeLenses ''HyperdataAnnuaire)

$(deriveJSON (unPrefix "_hc_") ''HyperdataCorpus)
$(deriveJSON (unPrefix "_ha_") ''HyperdataAnnuaire)

------------------------------------------------------------------------
instance ToSchema HyperdataCorpus where
  declareNamedSchema :: Proxy HyperdataCorpus -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy HyperdataCorpus
proxy =
    SchemaOptions
-> Proxy HyperdataCorpus
-> 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
"_hc_") Proxy HyperdataCorpus
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
"Corpus 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
?~ HyperdataCorpus -> Value
forall a. ToJSON a => a -> Value
toJSON HyperdataCorpus
defaultHyperdataCorpus

instance ToSchema HyperdataAnnuaire where
  declareNamedSchema :: Proxy HyperdataAnnuaire -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy HyperdataAnnuaire
proxy =
    SchemaOptions
-> Proxy HyperdataAnnuaire
-> 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
"_ha_") Proxy HyperdataAnnuaire
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
"Annuaire 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
?~ HyperdataAnnuaire -> Value
forall a. ToJSON a => a -> Value
toJSON HyperdataAnnuaire
defaultHyperdataAnnuaire
------------------------------------------------------------------------
instance Arbitrary HyperdataCorpus where
    arbitrary :: Gen HyperdataCorpus
arbitrary = HyperdataCorpus -> Gen HyperdataCorpus
forall (f :: * -> *) a. Applicative f => a -> f a
pure HyperdataCorpus
defaultHyperdataCorpus

instance Arbitrary HyperdataAnnuaire where
  arbitrary :: Gen HyperdataAnnuaire
arbitrary = HyperdataAnnuaire -> Gen HyperdataAnnuaire
forall (f :: * -> *) a. Applicative f => a -> f a
pure HyperdataAnnuaire
defaultHyperdataAnnuaire
------------------------------------------------------------------------
instance FromField HyperdataCorpus
  where
    fromField :: FieldParser HyperdataCorpus
fromField = FieldParser HyperdataCorpus
forall b.
(Typeable b, FromJSON b) =>
Field -> Maybe ByteString -> Conversion b
fromField'

instance FromField HyperdataAnnuaire
  where
    fromField :: FieldParser HyperdataAnnuaire
fromField = FieldParser HyperdataAnnuaire
forall b.
(Typeable b, FromJSON b) =>
Field -> Maybe ByteString -> Conversion b
fromField'
------------------------------------------------------------------------
instance DefaultFromField PGJsonb HyperdataCorpus
  where
    defaultFromField :: FromField PGJsonb HyperdataCorpus
defaultFromField = FromField PGJsonb HyperdataCorpus
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn

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