{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}

-- | Aeson schemas for communicating with the Docker Engine API
module Docker.API.Client.Internal.Schemas where

import Data.Aeson
import qualified Data.Text as T
import GHC.Generics (Generic)

-- | Constructs default Aeson options for serializing and deserializing objects in this module. This method
-- drops the first nPrefix characters from record accessors in your Haskell record before serializing to
-- JSON and uses the shortened field names to match record accessors when deserializing.
dockerParseOptions :: Int -> Options
dockerParseOptions :: Int -> Options
dockerParseOptions Int
nPrefix = Options
defaultOptions {fieldLabelModifier :: String -> String
fieldLabelModifier = Int -> String -> String
forall a. Int -> [a] -> [a]
drop Int
nPrefix}

-- | A Docker container's unique ID (in longer format)
type ContainerId = String

-----------------------------------------------------------------------------
--------------------- BEGIN LONG LIST OF SCHEMAS ----------------------------
-----------------------------------------------------------------------------

data CreateContainer = CreateContainer
  { CreateContainer -> Maybe Text
createContainerUser :: Maybe T.Text,
    CreateContainer -> Maybe [Text]
createContainerEnv :: Maybe [T.Text],
    CreateContainer -> Maybe [Text]
createContainerCmd :: Maybe [T.Text],
    CreateContainer -> Text
createContainerImage :: T.Text,
    CreateContainer -> Maybe Text
createContainerWorkingDir :: Maybe T.Text,
    CreateContainer -> Maybe HostConfig
createContainerHostConfig :: Maybe HostConfig
  }
  deriving ((forall x. CreateContainer -> Rep CreateContainer x)
-> (forall x. Rep CreateContainer x -> CreateContainer)
-> Generic CreateContainer
forall x. Rep CreateContainer x -> CreateContainer
forall x. CreateContainer -> Rep CreateContainer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateContainer x -> CreateContainer
$cfrom :: forall x. CreateContainer -> Rep CreateContainer x
Generic, Int -> CreateContainer -> String -> String
[CreateContainer] -> String -> String
CreateContainer -> String
(Int -> CreateContainer -> String -> String)
-> (CreateContainer -> String)
-> ([CreateContainer] -> String -> String)
-> Show CreateContainer
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [CreateContainer] -> String -> String
$cshowList :: [CreateContainer] -> String -> String
show :: CreateContainer -> String
$cshow :: CreateContainer -> String
showsPrec :: Int -> CreateContainer -> String -> String
$cshowsPrec :: Int -> CreateContainer -> String -> String
Show)

-- TODO: Write a method for generating binds which is a bit more safe
data HostConfig = HostConfig
  { HostConfig -> Maybe [Text]
hostConfigBinds :: Maybe [T.Text]
  }
  deriving ((forall x. HostConfig -> Rep HostConfig x)
-> (forall x. Rep HostConfig x -> HostConfig) -> Generic HostConfig
forall x. Rep HostConfig x -> HostConfig
forall x. HostConfig -> Rep HostConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HostConfig x -> HostConfig
$cfrom :: forall x. HostConfig -> Rep HostConfig x
Generic, Int -> HostConfig -> String -> String
[HostConfig] -> String -> String
HostConfig -> String
(Int -> HostConfig -> String -> String)
-> (HostConfig -> String)
-> ([HostConfig] -> String -> String)
-> Show HostConfig
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [HostConfig] -> String -> String
$cshowList :: [HostConfig] -> String -> String
show :: HostConfig -> String
$cshow :: HostConfig -> String
showsPrec :: Int -> HostConfig -> String -> String
$cshowsPrec :: Int -> HostConfig -> String -> String
Show)

data CreateContainerResponse = CreateContainerResponse
  { CreateContainerResponse -> String
createContainerResponseId :: ContainerId,
    CreateContainerResponse -> Maybe [Text]
createContainerResponseWarnings :: Maybe [T.Text]
  }
  deriving ((forall x.
 CreateContainerResponse -> Rep CreateContainerResponse x)
-> (forall x.
    Rep CreateContainerResponse x -> CreateContainerResponse)
-> Generic CreateContainerResponse
forall x. Rep CreateContainerResponse x -> CreateContainerResponse
forall x. CreateContainerResponse -> Rep CreateContainerResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateContainerResponse x -> CreateContainerResponse
$cfrom :: forall x. CreateContainerResponse -> Rep CreateContainerResponse x
Generic, Int -> CreateContainerResponse -> String -> String
[CreateContainerResponse] -> String -> String
CreateContainerResponse -> String
(Int -> CreateContainerResponse -> String -> String)
-> (CreateContainerResponse -> String)
-> ([CreateContainerResponse] -> String -> String)
-> Show CreateContainerResponse
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [CreateContainerResponse] -> String -> String
$cshowList :: [CreateContainerResponse] -> String -> String
show :: CreateContainerResponse -> String
$cshow :: CreateContainerResponse -> String
showsPrec :: Int -> CreateContainerResponse -> String -> String
$cshowsPrec :: Int -> CreateContainerResponse -> String -> String
Show)

data WaitContainerResponse = WaitContainerResponse
  { WaitContainerResponse -> Int
waitContainerResponseStatusCode :: Int,
    WaitContainerResponse -> Maybe WaitContainerError
waitContainerResponseError :: Maybe WaitContainerError
  }
  deriving ((forall x. WaitContainerResponse -> Rep WaitContainerResponse x)
-> (forall x. Rep WaitContainerResponse x -> WaitContainerResponse)
-> Generic WaitContainerResponse
forall x. Rep WaitContainerResponse x -> WaitContainerResponse
forall x. WaitContainerResponse -> Rep WaitContainerResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep WaitContainerResponse x -> WaitContainerResponse
$cfrom :: forall x. WaitContainerResponse -> Rep WaitContainerResponse x
Generic, Int -> WaitContainerResponse -> String -> String
[WaitContainerResponse] -> String -> String
WaitContainerResponse -> String
(Int -> WaitContainerResponse -> String -> String)
-> (WaitContainerResponse -> String)
-> ([WaitContainerResponse] -> String -> String)
-> Show WaitContainerResponse
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [WaitContainerResponse] -> String -> String
$cshowList :: [WaitContainerResponse] -> String -> String
show :: WaitContainerResponse -> String
$cshow :: WaitContainerResponse -> String
showsPrec :: Int -> WaitContainerResponse -> String -> String
$cshowsPrec :: Int -> WaitContainerResponse -> String -> String
Show)

data WaitContainerError = WaitContainerError
  { WaitContainerError -> Text
waitContainerErrorMessage :: T.Text
  }
  deriving ((forall x. WaitContainerError -> Rep WaitContainerError x)
-> (forall x. Rep WaitContainerError x -> WaitContainerError)
-> Generic WaitContainerError
forall x. Rep WaitContainerError x -> WaitContainerError
forall x. WaitContainerError -> Rep WaitContainerError x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep WaitContainerError x -> WaitContainerError
$cfrom :: forall x. WaitContainerError -> Rep WaitContainerError x
Generic, Int -> WaitContainerError -> String -> String
[WaitContainerError] -> String -> String
WaitContainerError -> String
(Int -> WaitContainerError -> String -> String)
-> (WaitContainerError -> String)
-> ([WaitContainerError] -> String -> String)
-> Show WaitContainerError
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [WaitContainerError] -> String -> String
$cshowList :: [WaitContainerError] -> String -> String
show :: WaitContainerError -> String
$cshow :: WaitContainerError -> String
showsPrec :: Int -> WaitContainerError -> String -> String
$cshowsPrec :: Int -> WaitContainerError -> String -> String
Show)

-----------------------------------------------------------------------------
----------- BEGIN LONG LIST OF SERIALIZER/DESERIALIZER INSTANCES-------------
-----------------------------------------------------------------------------

instance FromJSON HostConfig where parseJSON :: Value -> Parser HostConfig
parseJSON = Options -> Value -> Parser HostConfig
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON (Options -> Value -> Parser HostConfig)
-> Options -> Value -> Parser HostConfig
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
10

instance ToJSON HostConfig where
  toJSON :: HostConfig -> Value
toJSON = Options -> HostConfig -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON (Options -> HostConfig -> Value) -> Options -> HostConfig -> Value
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
10
  toEncoding :: HostConfig -> Encoding
toEncoding = Options -> HostConfig -> Encoding
forall a.
(Generic a, GToJSON' Encoding Zero (Rep a)) =>
Options -> a -> Encoding
genericToEncoding (Options -> HostConfig -> Encoding)
-> Options -> HostConfig -> Encoding
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
10

instance FromJSON CreateContainerResponse where parseJSON :: Value -> Parser CreateContainerResponse
parseJSON = Options -> Value -> Parser CreateContainerResponse
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON (Options -> Value -> Parser CreateContainerResponse)
-> Options -> Value -> Parser CreateContainerResponse
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
23

instance ToJSON CreateContainerResponse where
  toJSON :: CreateContainerResponse -> Value
toJSON = Options -> CreateContainerResponse -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON (Options -> CreateContainerResponse -> Value)
-> Options -> CreateContainerResponse -> Value
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
23
  toEncoding :: CreateContainerResponse -> Encoding
toEncoding = Options -> CreateContainerResponse -> Encoding
forall a.
(Generic a, GToJSON' Encoding Zero (Rep a)) =>
Options -> a -> Encoding
genericToEncoding (Options -> CreateContainerResponse -> Encoding)
-> Options -> CreateContainerResponse -> Encoding
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
23

instance FromJSON CreateContainer where parseJSON :: Value -> Parser CreateContainer
parseJSON = Options -> Value -> Parser CreateContainer
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON (Options -> Value -> Parser CreateContainer)
-> Options -> Value -> Parser CreateContainer
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
15

instance ToJSON CreateContainer where
  toJSON :: CreateContainer -> Value
toJSON = Options -> CreateContainer -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON (Options -> CreateContainer -> Value)
-> Options -> CreateContainer -> Value
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
15
  toEncoding :: CreateContainer -> Encoding
toEncoding = Options -> CreateContainer -> Encoding
forall a.
(Generic a, GToJSON' Encoding Zero (Rep a)) =>
Options -> a -> Encoding
genericToEncoding (Options -> CreateContainer -> Encoding)
-> Options -> CreateContainer -> Encoding
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
15

instance FromJSON WaitContainerResponse where parseJSON :: Value -> Parser WaitContainerResponse
parseJSON = Options -> Value -> Parser WaitContainerResponse
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON (Options -> Value -> Parser WaitContainerResponse)
-> Options -> Value -> Parser WaitContainerResponse
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
21

instance ToJSON WaitContainerResponse where
  toJSON :: WaitContainerResponse -> Value
toJSON = Options -> WaitContainerResponse -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON (Options -> WaitContainerResponse -> Value)
-> Options -> WaitContainerResponse -> Value
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
21
  toEncoding :: WaitContainerResponse -> Encoding
toEncoding = Options -> WaitContainerResponse -> Encoding
forall a.
(Generic a, GToJSON' Encoding Zero (Rep a)) =>
Options -> a -> Encoding
genericToEncoding (Options -> WaitContainerResponse -> Encoding)
-> Options -> WaitContainerResponse -> Encoding
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
21

instance FromJSON WaitContainerError where parseJSON :: Value -> Parser WaitContainerError
parseJSON = Options -> Value -> Parser WaitContainerError
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON (Options -> Value -> Parser WaitContainerError)
-> Options -> Value -> Parser WaitContainerError
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
18

instance ToJSON WaitContainerError where
  toJSON :: WaitContainerError -> Value
toJSON = Options -> WaitContainerError -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON (Options -> WaitContainerError -> Value)
-> Options -> WaitContainerError -> Value
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
18
  toEncoding :: WaitContainerError -> Encoding
toEncoding = Options -> WaitContainerError -> Encoding
forall a.
(Generic a, GToJSON' Encoding Zero (Rep a)) =>
Options -> a -> Encoding
genericToEncoding (Options -> WaitContainerError -> Encoding)
-> Options -> WaitContainerError -> Encoding
forall a b. (a -> b) -> a -> b
$ Int -> Options
dockerParseOptions Int
18