{-|
Module      : Gargantext.Database.Schema.NodeNode
Description : 
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

Here is a longer description of this module, containing some
commentary with @some markup@.
-}

{-# OPTIONS_GHC -fno-warn-orphans #-}

{-# LANGUAGE Arrows                 #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE QuasiQuotes            #-}
{-# LANGUAGE TemplateHaskell        #-}

module Gargantext.Database.Schema.NodeNode where

import Gargantext.Core.Types
import Gargantext.Database.Schema.Prelude
import Gargantext.Prelude


data NodeNodePoly node1_id node2_id score cat
                   = NodeNode { NodeNodePoly node1_id node2_id score cat -> node1_id
_nn_node1_id   :: !node1_id
                              , NodeNodePoly node1_id node2_id score cat -> node2_id
_nn_node2_id   :: !node2_id
                              , NodeNodePoly node1_id node2_id score cat -> score
_nn_score      :: !score
                              , NodeNodePoly node1_id node2_id score cat -> cat
_nn_category   :: !cat
                              } deriving (Int -> NodeNodePoly node1_id node2_id score cat -> ShowS
[NodeNodePoly node1_id node2_id score cat] -> ShowS
NodeNodePoly node1_id node2_id score cat -> String
(Int -> NodeNodePoly node1_id node2_id score cat -> ShowS)
-> (NodeNodePoly node1_id node2_id score cat -> String)
-> ([NodeNodePoly node1_id node2_id score cat] -> ShowS)
-> Show (NodeNodePoly node1_id node2_id score cat)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall node1_id node2_id score cat.
(Show node1_id, Show node2_id, Show score, Show cat) =>
Int -> NodeNodePoly node1_id node2_id score cat -> ShowS
forall node1_id node2_id score cat.
(Show node1_id, Show node2_id, Show score, Show cat) =>
[NodeNodePoly node1_id node2_id score cat] -> ShowS
forall node1_id node2_id score cat.
(Show node1_id, Show node2_id, Show score, Show cat) =>
NodeNodePoly node1_id node2_id score cat -> String
showList :: [NodeNodePoly node1_id node2_id score cat] -> ShowS
$cshowList :: forall node1_id node2_id score cat.
(Show node1_id, Show node2_id, Show score, Show cat) =>
[NodeNodePoly node1_id node2_id score cat] -> ShowS
show :: NodeNodePoly node1_id node2_id score cat -> String
$cshow :: forall node1_id node2_id score cat.
(Show node1_id, Show node2_id, Show score, Show cat) =>
NodeNodePoly node1_id node2_id score cat -> String
showsPrec :: Int -> NodeNodePoly node1_id node2_id score cat -> ShowS
$cshowsPrec :: forall node1_id node2_id score cat.
(Show node1_id, Show node2_id, Show score, Show cat) =>
Int -> NodeNodePoly node1_id node2_id score cat -> ShowS
Show)

type NodeNodeWrite     = NodeNodePoly (Column (PGInt4))
                                      (Column (PGInt4))
                                      (Maybe  (Column (PGFloat8)))
                                      (Maybe  (Column (PGInt4)))

type NodeNodeRead      = NodeNodePoly (Column (PGInt4))
                                      (Column (PGInt4))
                                      (Column (PGFloat8))
                                      (Column (PGInt4))

type NodeNodeReadNull  = NodeNodePoly (Column (Nullable PGInt4))
                                      (Column (Nullable PGInt4))
                                      (Column (Nullable PGFloat8))
                                      (Column (Nullable PGInt4))

type NodeNode = NodeNodePoly NodeId NodeId (Maybe Double) (Maybe Int)

$(makeAdaptorAndInstance "pNodeNode" ''NodeNodePoly)
makeLenses ''NodeNodePoly

nodeNodeTable :: Table NodeNodeWrite NodeNodeRead
nodeNodeTable :: Table NodeNodeWrite NodeNodeRead
nodeNodeTable  =
  String
-> TableFields NodeNodeWrite NodeNodeRead
-> Table NodeNodeWrite NodeNodeRead
forall writeFields viewFields.
String
-> TableFields writeFields viewFields
-> Table writeFields viewFields
Table String
"nodes_nodes"
         ( NodeNodePoly
  (TableFields (Column PGInt4) (Column PGInt4))
  (TableFields (Column PGInt4) (Column PGInt4))
  (TableFields (Maybe (Column PGFloat8)) (Column PGFloat8))
  (TableFields (Maybe (Column PGInt4)) (Column PGInt4))
-> TableFields NodeNodeWrite NodeNodeRead
forall (p :: * -> * -> *) a1_0 a2_0 a3_0 a4_0 a1_1 a2_1 a3_1 a4_1.
ProductProfunctor p =>
NodeNodePoly
  (p a1_0 a1_1) (p a2_0 a2_1) (p a3_0 a3_1) (p a4_0 a4_1)
-> p (NodeNodePoly a1_0 a2_0 a3_0 a4_0)
     (NodeNodePoly a1_1 a2_1 a3_1 a4_1)
pNodeNode
           NodeNode :: forall node1_id node2_id score cat.
node1_id
-> node2_id
-> score
-> cat
-> NodeNodePoly node1_id node2_id score cat
NodeNode { _nn_node1_id :: TableFields (Column PGInt4) (Column PGInt4)
_nn_node1_id = String -> TableFields (Column PGInt4) (Column PGInt4)
forall a. String -> TableFields (Column a) (Column a)
requiredTableField String
"node1_id"
                    , _nn_node2_id :: TableFields (Column PGInt4) (Column PGInt4)
_nn_node2_id = String -> TableFields (Column PGInt4) (Column PGInt4)
forall a. String -> TableFields (Column a) (Column a)
requiredTableField String
"node2_id"
                    , _nn_score :: TableFields (Maybe (Column PGFloat8)) (Column PGFloat8)
_nn_score    = String -> TableFields (Maybe (Column PGFloat8)) (Column PGFloat8)
forall a. String -> TableFields (Maybe (Column a)) (Column a)
optionalTableField String
"score"
                    , _nn_category :: TableFields (Maybe (Column PGInt4)) (Column PGInt4)
_nn_category = String -> TableFields (Maybe (Column PGInt4)) (Column PGInt4)
forall a. String -> TableFields (Maybe (Column a)) (Column a)
optionalTableField String
"category"
                    }
                )

instance DefaultFromField (Nullable PGInt4)   Int            where
    defaultFromField :: FromField (Nullable PGInt4) Int
defaultFromField = FromField (Nullable PGInt4) Int
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn

instance DefaultFromField (Nullable PGFloat8) Int            where
    defaultFromField :: FromField (Nullable PGFloat8) Int
defaultFromField = FromField (Nullable PGFloat8) Int
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn

instance DefaultFromField (Nullable PGFloat8) Double         where
    defaultFromField :: FromField (Nullable PGFloat8) Double
defaultFromField = FromField (Nullable PGFloat8) Double
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn

instance DefaultFromField PGFloat8            (Maybe Double) where
    defaultFromField :: FromField PGFloat8 (Maybe Double)
defaultFromField = FromField PGFloat8 (Maybe Double)
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn

instance DefaultFromField PGInt4              (Maybe Int)    where
    defaultFromField :: FromField PGInt4 (Maybe Int)
defaultFromField = FromField PGInt4 (Maybe Int)
forall haskell pgType.
FromField haskell =>
FromField pgType haskell
fieldQueryRunnerColumn