{-# LANGUAGE TemplateHaskell #-}

module PMS.Infra.Socket.DM.Type where

import Control.Monad.Logger
import Control.Monad.Reader
import Control.Monad.Except
import Control.Lens
import Data.Default
import Data.Aeson.TH
import qualified Control.Concurrent.STM as STM
import Network.Socket
import Data.Word 

import qualified PMS.Domain.Model.DM.Type as DM
import qualified PMS.Domain.Model.DM.TH as DM

-- |
--
data AppData = AppData {
               AppData -> TMVar (Maybe Socket)
_socketAppData :: STM.TMVar (Maybe Socket)
             , AppData -> TMVar ()
_lockAppData :: STM.TMVar ()
             , AppData -> JsonRpcRequest
_jsonrpcAppData :: DM.JsonRpcRequest
             }

makeLenses ''AppData

defaultAppData :: IO AppData
defaultAppData :: IO AppData
defaultAppData = do
  TMVar (Maybe Socket)
mgrVar <- Maybe Socket -> IO (TMVar (Maybe Socket))
forall a. a -> IO (TMVar a)
STM.newTMVarIO Maybe Socket
forall a. Maybe a
Nothing
  TMVar ()
lock    <- () -> IO (TMVar ())
forall a. a -> IO (TMVar a)
STM.newTMVarIO ()
  AppData -> IO AppData
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return AppData {
           _socketAppData :: TMVar (Maybe Socket)
_socketAppData = TMVar (Maybe Socket)
mgrVar
         , _lockAppData :: TMVar ()
_lockAppData = TMVar ()
lock
         , _jsonrpcAppData :: JsonRpcRequest
_jsonrpcAppData = JsonRpcRequest
forall a. Default a => a
def
         }

-- |
--
type AppContext = ReaderT AppData (ReaderT DM.DomainData (ExceptT DM.ErrorData (LoggingT IO)))

-- |
--
type IOTask = IO


--------------------------------------------------------------------------------------------
-- |
--
data SocketStringToolParams =
  SocketStringToolParams {
    SocketStringToolParams -> String
_argumentsSocketStringToolParams :: String
  } deriving (Int -> SocketStringToolParams -> ShowS
[SocketStringToolParams] -> ShowS
SocketStringToolParams -> String
(Int -> SocketStringToolParams -> ShowS)
-> (SocketStringToolParams -> String)
-> ([SocketStringToolParams] -> ShowS)
-> Show SocketStringToolParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SocketStringToolParams -> ShowS
showsPrec :: Int -> SocketStringToolParams -> ShowS
$cshow :: SocketStringToolParams -> String
show :: SocketStringToolParams -> String
$cshowList :: [SocketStringToolParams] -> ShowS
showList :: [SocketStringToolParams] -> ShowS
Show, ReadPrec [SocketStringToolParams]
ReadPrec SocketStringToolParams
Int -> ReadS SocketStringToolParams
ReadS [SocketStringToolParams]
(Int -> ReadS SocketStringToolParams)
-> ReadS [SocketStringToolParams]
-> ReadPrec SocketStringToolParams
-> ReadPrec [SocketStringToolParams]
-> Read SocketStringToolParams
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SocketStringToolParams
readsPrec :: Int -> ReadS SocketStringToolParams
$creadList :: ReadS [SocketStringToolParams]
readList :: ReadS [SocketStringToolParams]
$creadPrec :: ReadPrec SocketStringToolParams
readPrec :: ReadPrec SocketStringToolParams
$creadListPrec :: ReadPrec [SocketStringToolParams]
readListPrec :: ReadPrec [SocketStringToolParams]
Read, SocketStringToolParams -> SocketStringToolParams -> Bool
(SocketStringToolParams -> SocketStringToolParams -> Bool)
-> (SocketStringToolParams -> SocketStringToolParams -> Bool)
-> Eq SocketStringToolParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SocketStringToolParams -> SocketStringToolParams -> Bool
== :: SocketStringToolParams -> SocketStringToolParams -> Bool
$c/= :: SocketStringToolParams -> SocketStringToolParams -> Bool
/= :: SocketStringToolParams -> SocketStringToolParams -> Bool
Eq)

$(deriveJSON defaultOptions {fieldLabelModifier = DM.dropDataName "SocketStringToolParams", omitNothingFields = True} ''SocketStringToolParams)
makeLenses ''SocketStringToolParams

instance Default SocketStringToolParams where
  def :: SocketStringToolParams
def = SocketStringToolParams {
        _argumentsSocketStringToolParams :: String
_argumentsSocketStringToolParams = String
forall a. Default a => a
def
      }

-- |
--
data SocketIntToolParams =
  SocketIntToolParams {
    SocketIntToolParams -> Int
_sizeSocketIntToolParams :: Int
  } deriving (Int -> SocketIntToolParams -> ShowS
[SocketIntToolParams] -> ShowS
SocketIntToolParams -> String
(Int -> SocketIntToolParams -> ShowS)
-> (SocketIntToolParams -> String)
-> ([SocketIntToolParams] -> ShowS)
-> Show SocketIntToolParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SocketIntToolParams -> ShowS
showsPrec :: Int -> SocketIntToolParams -> ShowS
$cshow :: SocketIntToolParams -> String
show :: SocketIntToolParams -> String
$cshowList :: [SocketIntToolParams] -> ShowS
showList :: [SocketIntToolParams] -> ShowS
Show, ReadPrec [SocketIntToolParams]
ReadPrec SocketIntToolParams
Int -> ReadS SocketIntToolParams
ReadS [SocketIntToolParams]
(Int -> ReadS SocketIntToolParams)
-> ReadS [SocketIntToolParams]
-> ReadPrec SocketIntToolParams
-> ReadPrec [SocketIntToolParams]
-> Read SocketIntToolParams
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SocketIntToolParams
readsPrec :: Int -> ReadS SocketIntToolParams
$creadList :: ReadS [SocketIntToolParams]
readList :: ReadS [SocketIntToolParams]
$creadPrec :: ReadPrec SocketIntToolParams
readPrec :: ReadPrec SocketIntToolParams
$creadListPrec :: ReadPrec [SocketIntToolParams]
readListPrec :: ReadPrec [SocketIntToolParams]
Read, SocketIntToolParams -> SocketIntToolParams -> Bool
(SocketIntToolParams -> SocketIntToolParams -> Bool)
-> (SocketIntToolParams -> SocketIntToolParams -> Bool)
-> Eq SocketIntToolParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SocketIntToolParams -> SocketIntToolParams -> Bool
== :: SocketIntToolParams -> SocketIntToolParams -> Bool
$c/= :: SocketIntToolParams -> SocketIntToolParams -> Bool
/= :: SocketIntToolParams -> SocketIntToolParams -> Bool
Eq)

$(deriveJSON defaultOptions {fieldLabelModifier = DM.dropDataName "SocketIntToolParams", omitNothingFields = True} ''SocketIntToolParams)
makeLenses ''SocketIntToolParams

instance Default SocketIntToolParams where
  def :: SocketIntToolParams
def = SocketIntToolParams {
        _sizeSocketIntToolParams :: Int
_sizeSocketIntToolParams = Int
forall a. Default a => a
def
      }


-- |
--
data SocketWord8ArrayToolParams =
  SocketWord8ArrayToolParams {
    SocketWord8ArrayToolParams -> [Word8]
_dataSocketWord8ArrayToolParams :: [Word8]
  } deriving (Int -> SocketWord8ArrayToolParams -> ShowS
[SocketWord8ArrayToolParams] -> ShowS
SocketWord8ArrayToolParams -> String
(Int -> SocketWord8ArrayToolParams -> ShowS)
-> (SocketWord8ArrayToolParams -> String)
-> ([SocketWord8ArrayToolParams] -> ShowS)
-> Show SocketWord8ArrayToolParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SocketWord8ArrayToolParams -> ShowS
showsPrec :: Int -> SocketWord8ArrayToolParams -> ShowS
$cshow :: SocketWord8ArrayToolParams -> String
show :: SocketWord8ArrayToolParams -> String
$cshowList :: [SocketWord8ArrayToolParams] -> ShowS
showList :: [SocketWord8ArrayToolParams] -> ShowS
Show, ReadPrec [SocketWord8ArrayToolParams]
ReadPrec SocketWord8ArrayToolParams
Int -> ReadS SocketWord8ArrayToolParams
ReadS [SocketWord8ArrayToolParams]
(Int -> ReadS SocketWord8ArrayToolParams)
-> ReadS [SocketWord8ArrayToolParams]
-> ReadPrec SocketWord8ArrayToolParams
-> ReadPrec [SocketWord8ArrayToolParams]
-> Read SocketWord8ArrayToolParams
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SocketWord8ArrayToolParams
readsPrec :: Int -> ReadS SocketWord8ArrayToolParams
$creadList :: ReadS [SocketWord8ArrayToolParams]
readList :: ReadS [SocketWord8ArrayToolParams]
$creadPrec :: ReadPrec SocketWord8ArrayToolParams
readPrec :: ReadPrec SocketWord8ArrayToolParams
$creadListPrec :: ReadPrec [SocketWord8ArrayToolParams]
readListPrec :: ReadPrec [SocketWord8ArrayToolParams]
Read, SocketWord8ArrayToolParams -> SocketWord8ArrayToolParams -> Bool
(SocketWord8ArrayToolParams -> SocketWord8ArrayToolParams -> Bool)
-> (SocketWord8ArrayToolParams
    -> SocketWord8ArrayToolParams -> Bool)
-> Eq SocketWord8ArrayToolParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SocketWord8ArrayToolParams -> SocketWord8ArrayToolParams -> Bool
== :: SocketWord8ArrayToolParams -> SocketWord8ArrayToolParams -> Bool
$c/= :: SocketWord8ArrayToolParams -> SocketWord8ArrayToolParams -> Bool
/= :: SocketWord8ArrayToolParams -> SocketWord8ArrayToolParams -> Bool
Eq)

$(deriveJSON defaultOptions {fieldLabelModifier = DM.dropDataName "SocketWord8ArrayToolParams", omitNothingFields = True} ''SocketWord8ArrayToolParams)
makeLenses ''SocketWord8ArrayToolParams

instance Default SocketWord8ArrayToolParams where
  def :: SocketWord8ArrayToolParams
def = SocketWord8ArrayToolParams {
        _dataSocketWord8ArrayToolParams :: [Word8]
_dataSocketWord8ArrayToolParams = [Word8]
forall a. Default a => a
def
      }


-- |
--
data SocketCommandToolParams =
  SocketCommandToolParams {
    SocketCommandToolParams -> String
_commandSocketCommandToolParams   :: String
  , SocketCommandToolParams -> Maybe [String]
_argumentsSocketCommandToolParams :: Maybe [String]
  } deriving (Int -> SocketCommandToolParams -> ShowS
[SocketCommandToolParams] -> ShowS
SocketCommandToolParams -> String
(Int -> SocketCommandToolParams -> ShowS)
-> (SocketCommandToolParams -> String)
-> ([SocketCommandToolParams] -> ShowS)
-> Show SocketCommandToolParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SocketCommandToolParams -> ShowS
showsPrec :: Int -> SocketCommandToolParams -> ShowS
$cshow :: SocketCommandToolParams -> String
show :: SocketCommandToolParams -> String
$cshowList :: [SocketCommandToolParams] -> ShowS
showList :: [SocketCommandToolParams] -> ShowS
Show, ReadPrec [SocketCommandToolParams]
ReadPrec SocketCommandToolParams
Int -> ReadS SocketCommandToolParams
ReadS [SocketCommandToolParams]
(Int -> ReadS SocketCommandToolParams)
-> ReadS [SocketCommandToolParams]
-> ReadPrec SocketCommandToolParams
-> ReadPrec [SocketCommandToolParams]
-> Read SocketCommandToolParams
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SocketCommandToolParams
readsPrec :: Int -> ReadS SocketCommandToolParams
$creadList :: ReadS [SocketCommandToolParams]
readList :: ReadS [SocketCommandToolParams]
$creadPrec :: ReadPrec SocketCommandToolParams
readPrec :: ReadPrec SocketCommandToolParams
$creadListPrec :: ReadPrec [SocketCommandToolParams]
readListPrec :: ReadPrec [SocketCommandToolParams]
Read, SocketCommandToolParams -> SocketCommandToolParams -> Bool
(SocketCommandToolParams -> SocketCommandToolParams -> Bool)
-> (SocketCommandToolParams -> SocketCommandToolParams -> Bool)
-> Eq SocketCommandToolParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SocketCommandToolParams -> SocketCommandToolParams -> Bool
== :: SocketCommandToolParams -> SocketCommandToolParams -> Bool
$c/= :: SocketCommandToolParams -> SocketCommandToolParams -> Bool
/= :: SocketCommandToolParams -> SocketCommandToolParams -> Bool
Eq)

$(deriveJSON defaultOptions {fieldLabelModifier = DM.dropDataName "SocketCommandToolParams", omitNothingFields = True} ''SocketCommandToolParams)
makeLenses ''SocketCommandToolParams

instance Default SocketCommandToolParams where
  def :: SocketCommandToolParams
def = SocketCommandToolParams {
        _commandSocketCommandToolParams :: String
_commandSocketCommandToolParams   = String
forall a. Default a => a
def
      , _argumentsSocketCommandToolParams :: Maybe [String]
_argumentsSocketCommandToolParams = Maybe [String]
forall a. Default a => a
def
      }


-- |
--
data SocketToolParams =
  SocketToolParams {
    SocketToolParams -> String
_hostSocketToolParams :: String
  , SocketToolParams -> String
_portSocketToolParams :: String
  } deriving (Int -> SocketToolParams -> ShowS
[SocketToolParams] -> ShowS
SocketToolParams -> String
(Int -> SocketToolParams -> ShowS)
-> (SocketToolParams -> String)
-> ([SocketToolParams] -> ShowS)
-> Show SocketToolParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SocketToolParams -> ShowS
showsPrec :: Int -> SocketToolParams -> ShowS
$cshow :: SocketToolParams -> String
show :: SocketToolParams -> String
$cshowList :: [SocketToolParams] -> ShowS
showList :: [SocketToolParams] -> ShowS
Show, ReadPrec [SocketToolParams]
ReadPrec SocketToolParams
Int -> ReadS SocketToolParams
ReadS [SocketToolParams]
(Int -> ReadS SocketToolParams)
-> ReadS [SocketToolParams]
-> ReadPrec SocketToolParams
-> ReadPrec [SocketToolParams]
-> Read SocketToolParams
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SocketToolParams
readsPrec :: Int -> ReadS SocketToolParams
$creadList :: ReadS [SocketToolParams]
readList :: ReadS [SocketToolParams]
$creadPrec :: ReadPrec SocketToolParams
readPrec :: ReadPrec SocketToolParams
$creadListPrec :: ReadPrec [SocketToolParams]
readListPrec :: ReadPrec [SocketToolParams]
Read, SocketToolParams -> SocketToolParams -> Bool
(SocketToolParams -> SocketToolParams -> Bool)
-> (SocketToolParams -> SocketToolParams -> Bool)
-> Eq SocketToolParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SocketToolParams -> SocketToolParams -> Bool
== :: SocketToolParams -> SocketToolParams -> Bool
$c/= :: SocketToolParams -> SocketToolParams -> Bool
/= :: SocketToolParams -> SocketToolParams -> Bool
Eq)

$(deriveJSON defaultOptions {fieldLabelModifier = DM.dropDataName "SocketToolParams", omitNothingFields = True} ''SocketToolParams)
makeLenses ''SocketToolParams

instance Default SocketToolParams where
  def :: SocketToolParams
def = SocketToolParams {
        _hostSocketToolParams :: String
_hostSocketToolParams   = String
forall a. Default a => a
def
      , _portSocketToolParams :: String
_portSocketToolParams = String
forall a. Default a => a
def
      }

-- |
--
data SocketStringArrayToolParams =
  SocketStringArrayToolParams {
    SocketStringArrayToolParams -> [String]
_argumentsSocketStringArrayToolParams :: [String]
  } deriving (Int -> SocketStringArrayToolParams -> ShowS
[SocketStringArrayToolParams] -> ShowS
SocketStringArrayToolParams -> String
(Int -> SocketStringArrayToolParams -> ShowS)
-> (SocketStringArrayToolParams -> String)
-> ([SocketStringArrayToolParams] -> ShowS)
-> Show SocketStringArrayToolParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SocketStringArrayToolParams -> ShowS
showsPrec :: Int -> SocketStringArrayToolParams -> ShowS
$cshow :: SocketStringArrayToolParams -> String
show :: SocketStringArrayToolParams -> String
$cshowList :: [SocketStringArrayToolParams] -> ShowS
showList :: [SocketStringArrayToolParams] -> ShowS
Show, ReadPrec [SocketStringArrayToolParams]
ReadPrec SocketStringArrayToolParams
Int -> ReadS SocketStringArrayToolParams
ReadS [SocketStringArrayToolParams]
(Int -> ReadS SocketStringArrayToolParams)
-> ReadS [SocketStringArrayToolParams]
-> ReadPrec SocketStringArrayToolParams
-> ReadPrec [SocketStringArrayToolParams]
-> Read SocketStringArrayToolParams
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SocketStringArrayToolParams
readsPrec :: Int -> ReadS SocketStringArrayToolParams
$creadList :: ReadS [SocketStringArrayToolParams]
readList :: ReadS [SocketStringArrayToolParams]
$creadPrec :: ReadPrec SocketStringArrayToolParams
readPrec :: ReadPrec SocketStringArrayToolParams
$creadListPrec :: ReadPrec [SocketStringArrayToolParams]
readListPrec :: ReadPrec [SocketStringArrayToolParams]
Read, SocketStringArrayToolParams -> SocketStringArrayToolParams -> Bool
(SocketStringArrayToolParams
 -> SocketStringArrayToolParams -> Bool)
-> (SocketStringArrayToolParams
    -> SocketStringArrayToolParams -> Bool)
-> Eq SocketStringArrayToolParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SocketStringArrayToolParams -> SocketStringArrayToolParams -> Bool
== :: SocketStringArrayToolParams -> SocketStringArrayToolParams -> Bool
$c/= :: SocketStringArrayToolParams -> SocketStringArrayToolParams -> Bool
/= :: SocketStringArrayToolParams -> SocketStringArrayToolParams -> Bool
Eq)

$(deriveJSON defaultOptions {fieldLabelModifier = DM.dropDataName "SocketStringArrayToolParams", omitNothingFields = True} ''SocketStringArrayToolParams)
makeLenses ''SocketStringArrayToolParams

instance Default SocketStringArrayToolParams where
  def :: SocketStringArrayToolParams
def = SocketStringArrayToolParams {
        _argumentsSocketStringArrayToolParams :: [String]
_argumentsSocketStringArrayToolParams = [String]
forall a. Default a => a
def
      }