-----------------------------------------------------------------
-- Autogenerated by Thrift
--
-- DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
--  @generated
-----------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_GHC -fno-warn-unused-imports#-}
{-# OPTIONS_GHC -fno-warn-overlapping-patterns#-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns#-}
{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns#-}
{-# OPTIONS_GHC -fno-warn-incomplete-record-updates#-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Thrift.Protocol.RpcOptions.Types
       (Priority(HighImportant, High, Important, NormalPriority,
                 BestEffort, Priority__UNKNOWN),
        RpcOptions(RpcOptions, rpc_timeout, rpc_priority, rpc_chunkTimeout,
                   rpc_queueTimeout, rpc_headers))
       where
import qualified Control.DeepSeq as DeepSeq
import qualified Control.Exception as Exception
import qualified Control.Monad as Monad
import qualified Control.Monad.ST.Trans as ST
import qualified Control.Monad.Trans.Class as Trans
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Types as Aeson
import qualified Data.Default as Default
import qualified Data.Function as Function
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Hashable as Hashable
import qualified Data.Int as Int
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import qualified Data.Ord as Ord
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified GHC.Magic as GHC
import qualified Prelude as Prelude
import qualified Thrift.Binary.Parser as Parser
import qualified Thrift.CodegenTypesOnly as Thrift
import Control.Applicative ((<|>), (*>), (<*))
import Data.Aeson ((.:), (.:?), (.=), (.!=))
import Data.Monoid ((<>))
import Prelude ((.), (++), (>), (==))
import Prelude ((.), (<$>), (<*>), (>>=), (==), (/=), (<), (++))

data Priority = HighImportant
              | High
              | Important
              | NormalPriority
              | BestEffort
              | Priority__UNKNOWN Prelude.Int
                deriving (Prelude.Eq, Prelude.Show, Prelude.Ord)

instance Aeson.ToJSON Priority where
  toJSON = Aeson.toJSON . Thrift.fromThriftEnum

instance DeepSeq.NFData Priority where
  rnf __Priority = Prelude.seq __Priority ()

instance Default.Default Priority where
  def = HighImportant

instance Hashable.Hashable Priority where
  hashWithSalt _salt _val
    = Hashable.hashWithSalt _salt (Thrift.fromThriftEnum _val)

instance Thrift.ThriftEnum Priority where
  toThriftEnum 0 = HighImportant
  toThriftEnum 1 = High
  toThriftEnum 2 = Important
  toThriftEnum 3 = NormalPriority
  toThriftEnum 4 = BestEffort
  toThriftEnum val = Priority__UNKNOWN val
  fromThriftEnum HighImportant = 0
  fromThriftEnum High = 1
  fromThriftEnum Important = 2
  fromThriftEnum NormalPriority = 3
  fromThriftEnum BestEffort = 4
  fromThriftEnum (Priority__UNKNOWN val) = val
  allThriftEnumValues
    = [HighImportant, High, Important, NormalPriority, BestEffort]
  toThriftEnumEither 0 = Prelude.Right HighImportant
  toThriftEnumEither 1 = Prelude.Right High
  toThriftEnumEither 2 = Prelude.Right Important
  toThriftEnumEither 3 = Prelude.Right NormalPriority
  toThriftEnumEither 4 = Prelude.Right BestEffort
  toThriftEnumEither val
    = Prelude.Left
        ("toThriftEnumEither: not a valid identifier for enum Priority: "
           ++ Prelude.show val)

data RpcOptions = RpcOptions{rpc_timeout :: Int.Int32,
                             rpc_priority :: Prelude.Maybe Priority,
                             rpc_chunkTimeout :: Int.Int32, rpc_queueTimeout :: Int.Int32,
                             rpc_headers :: Prelude.Maybe (Map.Map Text.Text Text.Text)}
                  deriving (Prelude.Eq, Prelude.Show, Prelude.Ord)

instance Aeson.ToJSON RpcOptions where
  toJSON
    (RpcOptions __field__timeout __field__priority
       __field__chunkTimeout __field__queueTimeout __field__headers)
    = Aeson.object
        ("timeout" .= __field__timeout :
           Prelude.maybe Prelude.id ((:) . ("priority" .=)) __field__priority
             ("chunkTimeout" .= __field__chunkTimeout :
                "queueTimeout" .= __field__queueTimeout :
                  Prelude.maybe Prelude.id ((:) . ("headers" .=)) __field__headers
                    Prelude.mempty))

instance Thrift.ThriftStruct RpcOptions where
  buildStruct _proxy
    (RpcOptions __field__timeout __field__priority
       __field__chunkTimeout __field__queueTimeout __field__headers)
    = Thrift.genStruct _proxy
        (Thrift.genFieldPrim _proxy "timeout" (Thrift.getI32Type _proxy) 1
           0
           (Thrift.genI32Prim _proxy)
           __field__timeout
           :
           let (__cereal__priority, __id__priority)
                 = case __field__priority of
                     Prelude.Just _val -> ((:)
                                             (Thrift.genField _proxy "priority"
                                                (Thrift.getI32Type _proxy)
                                                2
                                                1
                                                ((Thrift.genI32 _proxy . Prelude.fromIntegral .
                                                    Thrift.fromThriftEnum)
                                                   _val)),
                                           2)
                     Prelude.Nothing -> (Prelude.id, 1)
             in
             __cereal__priority
               (Thrift.genFieldPrim _proxy "chunkTimeout"
                  (Thrift.getI32Type _proxy)
                  3
                  __id__priority
                  (Thrift.genI32Prim _proxy)
                  __field__chunkTimeout
                  :
                  Thrift.genFieldPrim _proxy "queueTimeout"
                    (Thrift.getI32Type _proxy)
                    4
                    3
                    (Thrift.genI32Prim _proxy)
                    __field__queueTimeout
                    :
                    case __field__headers of
                      Prelude.Just _val -> Thrift.genField _proxy "headers"
                                             (Thrift.getMapType _proxy)
                                             5
                                             4
                                             ((Thrift.genMap _proxy (Thrift.getStringType _proxy)
                                                 (Thrift.getStringType _proxy)
                                                 Prelude.True
                                                 (Thrift.genText _proxy)
                                                 (Thrift.genText _proxy)
                                                 . Map.toList)
                                                _val)
                                             : []
                      Prelude.Nothing -> []))
  parseStruct _proxy
    = ST.runSTT
        (do Prelude.return ()
            __field__timeout <- ST.newSTRef Default.def
            __field__priority <- ST.newSTRef Prelude.Nothing
            __field__chunkTimeout <- ST.newSTRef Default.def
            __field__queueTimeout <- ST.newSTRef Default.def
            __field__headers <- ST.newSTRef Prelude.Nothing
            let
              _parse _lastId
                = do _fieldBegin <- Trans.lift
                                      (Thrift.parseFieldBegin _proxy _lastId _idMap)
                     case _fieldBegin of
                       Thrift.FieldBegin _type _id _bool -> do case _id of
                                                                 1 | _type ==
                                                                       Thrift.getI32Type _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Thrift.parseI32
                                                                                      _proxy)
                                                                        ST.writeSTRef
                                                                          __field__timeout
                                                                          _val
                                                                 2 | _type ==
                                                                       Thrift.getI32Type _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Thrift.parseEnum
                                                                                      _proxy
                                                                                      "Priority")
                                                                        ST.writeSTRef
                                                                          __field__priority
                                                                          (Prelude.Just _val)
                                                                 3 | _type ==
                                                                       Thrift.getI32Type _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Thrift.parseI32
                                                                                      _proxy)
                                                                        ST.writeSTRef
                                                                          __field__chunkTimeout
                                                                          _val
                                                                 4 | _type ==
                                                                       Thrift.getI32Type _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Thrift.parseI32
                                                                                      _proxy)
                                                                        ST.writeSTRef
                                                                          __field__queueTimeout
                                                                          _val
                                                                 5 | _type ==
                                                                       Thrift.getMapType _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Map.fromList <$>
                                                                                      Thrift.parseMap
                                                                                        _proxy
                                                                                        (Thrift.parseText
                                                                                           _proxy)
                                                                                        (Thrift.parseText
                                                                                           _proxy)
                                                                                        Prelude.True)
                                                                        ST.writeSTRef
                                                                          __field__headers
                                                                          (Prelude.Just _val)
                                                                 _ -> Trans.lift
                                                                        (Thrift.parseSkip _proxy
                                                                           _type
                                                                           (Prelude.Just _bool))
                                                               _parse _id
                       Thrift.FieldEnd -> do !__val__timeout <- ST.readSTRef
                                                                  __field__timeout
                                             !__val__priority <- ST.readSTRef __field__priority
                                             !__val__chunkTimeout <- ST.readSTRef
                                                                       __field__chunkTimeout
                                             !__val__queueTimeout <- ST.readSTRef
                                                                       __field__queueTimeout
                                             !__val__headers <- ST.readSTRef __field__headers
                                             Prelude.pure
                                               (RpcOptions __val__timeout __val__priority
                                                  __val__chunkTimeout
                                                  __val__queueTimeout
                                                  __val__headers)
              _idMap
                = HashMap.fromList
                    [("timeout", 1), ("priority", 2), ("chunkTimeout", 3),
                     ("queueTimeout", 4), ("headers", 5)]
            _parse 0)

instance DeepSeq.NFData RpcOptions where
  rnf
    (RpcOptions __field__timeout __field__priority
       __field__chunkTimeout __field__queueTimeout __field__headers)
    = DeepSeq.rnf __field__timeout `Prelude.seq`
        DeepSeq.rnf __field__priority `Prelude.seq`
          DeepSeq.rnf __field__chunkTimeout `Prelude.seq`
            DeepSeq.rnf __field__queueTimeout `Prelude.seq`
              DeepSeq.rnf __field__headers `Prelude.seq` ()

instance Default.Default RpcOptions where
  def
    = RpcOptions Default.def Prelude.Nothing Default.def Default.def
        Prelude.Nothing

instance Hashable.Hashable RpcOptions where
  hashWithSalt __salt
    (RpcOptions _timeout _priority _chunkTimeout _queueTimeout
       _headers)
    = Hashable.hashWithSalt
        (Hashable.hashWithSalt
           (Hashable.hashWithSalt
              (Hashable.hashWithSalt (Hashable.hashWithSalt __salt _timeout)
                 _priority)
              _chunkTimeout)
           _queueTimeout)
        (Prelude.fmap
           (Prelude.map (\ (_k, _v) -> (_k, _v)) . Map.toAscList)
           _headers)