{-|
Module      : Gargantext.Core.Text.Corpus.API
Description : All crawlers of Gargantext in one file.
Copyright   : (c) CNRS, 2017
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

-}

module Gargantext.Core.Text.Corpus.API
  ( ExternalAPIs(..)
  , Query
  , Limit
  , get
  , externalAPIs
  )
    where

import Data.Maybe
import Gargantext.API.Admin.Orchestrator.Types (ExternalAPIs(..), externalAPIs)
import Gargantext.Core (Lang(..))
import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..))
import Gargantext.Prelude
import qualified Gargantext.Core.Text.Corpus.API.Hal     as HAL
import qualified Gargantext.Core.Text.Corpus.API.Isidore as ISIDORE
import qualified Gargantext.Core.Text.Corpus.API.Istex   as ISTEX
import qualified Gargantext.Core.Text.Corpus.API.Pubmed  as PUBMED

-- | TODO put in gargantext.init
default_limit :: Maybe Integer
default_limit :: Maybe Integer
default_limit = Integer -> Maybe Integer
forall a. a -> Maybe a
Just Integer
10000

-- | Get External API metadata main function
get :: ExternalAPIs
    -> Lang
    -> Query
    -> Maybe Limit
    -> IO [HyperdataDocument]
get :: ExternalAPIs
-> Lang -> Query -> Maybe Integer -> IO [HyperdataDocument]
get ExternalAPIs
PubMed  Lang
_la Query
q Maybe Integer
_l = Query -> Maybe Integer -> IO [HyperdataDocument]
PUBMED.get   Query
q Maybe Integer
default_limit -- EN only by default
get ExternalAPIs
HAL      Lang
la Query
q Maybe Integer
_l = Lang -> Query -> Maybe Integer -> IO [HyperdataDocument]
HAL.get   Lang
la Query
q Maybe Integer
default_limit
get ExternalAPIs
IsTex    Lang
la Query
q Maybe Integer
_l = Lang -> Query -> Maybe Integer -> IO [HyperdataDocument]
ISTEX.get Lang
la Query
q Maybe Integer
default_limit
get ExternalAPIs
Isidore  Lang
la Query
q Maybe Integer
_l = Lang
-> Maybe Limit
-> Maybe Query
-> Maybe Query
-> IO [HyperdataDocument]
ISIDORE.get Lang
la (Integer -> Limit
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Limit) -> Maybe Integer -> Maybe Limit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Integer
default_limit) (Query -> Maybe Query
forall a. a -> Maybe a
Just Query
q) Maybe Query
forall a. Maybe a
Nothing
get ExternalAPIs
_        Lang
_  Query
_ Maybe Integer
_ = IO [HyperdataDocument]
forall a. HasCallStack => a
undefined

-- | Some Sugar for the documentation
type Query = PUBMED.Query
type Limit = PUBMED.Limit