{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-missing-fields #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-----------------------------------------------------------------
-- Autogenerated by Thrift Compiler (0.9.2)                      --
--                                                             --
-- DO NOT EDIT UNLESS YOU ARE SURE YOU KNOW WHAT YOU ARE DOING --
-----------------------------------------------------------------

module Greet_Types where
import Prelude (($), (.), (>>=), (==), (++))
import qualified Prelude as P
import qualified Control.Exception as X
import qualified Control.Monad as M ( liftM, ap, when )
import Data.Functor ( (<$>) )
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Hashable as H
import qualified Data.Int as I
import qualified Data.Maybe as M (catMaybes)
import qualified Data.Text.Lazy.Encoding as E ( decodeUtf8, encodeUtf8 )
import qualified Data.Text.Lazy as LT
import qualified Data.Typeable as TY ( Typeable )
import qualified Data.HashMap.Strict as Map
import qualified Data.HashSet as Set
import qualified Data.Vector as Vector
import qualified Test.QuickCheck.Arbitrary as QC ( Arbitrary(..) )
import qualified Test.QuickCheck as QC ( elements )

import qualified Thrift as T
import qualified Thrift.Types as T
import qualified Thrift.Arbitraries as T


data Message = Message  { message_msg :: LT.Text
  } deriving (P.Show,P.Eq,TY.Typeable)
instance H.Hashable Message where
  hashWithSalt salt record = salt   `H.hashWithSalt` message_msg record  
instance QC.Arbitrary Message where 
  arbitrary = M.liftM Message (QC.arbitrary)
  shrink obj | obj == default_Message = []
             | P.otherwise = M.catMaybes
    [ if obj == default_Message{message_msg = message_msg obj} then P.Nothing else P.Just $ default_Message{message_msg = message_msg obj}
    ]
from_Message :: Message -> T.ThriftVal
from_Message record = T.TStruct $ Map.fromList $ M.catMaybes
  [ (\_v2 -> P.Just (1, ("msg",T.TString $ E.encodeUtf8 _v2))) $ message_msg record
  ]
write_Message :: (T.Protocol p, T.Transport t) => p t -> Message -> P.IO ()
write_Message oprot record = T.writeVal oprot $ from_Message record
encode_Message :: (T.Protocol p, T.Transport t) => p t -> Message -> LBS.ByteString
encode_Message oprot record = T.serializeVal oprot $ from_Message record
to_Message :: T.ThriftVal -> Message
to_Message (T.TStruct fields) = Message{
  message_msg = P.maybe (message_msg default_Message) (\(_,_val4) -> (case _val4 of {T.TString _val5 -> E.decodeUtf8 _val5; _ -> P.error "wrong type"})) (Map.lookup (1) fields)
  }
to_Message _ = P.error "not a struct"
read_Message :: (T.Transport t, T.Protocol p) => p t -> P.IO Message
read_Message iprot = to_Message <$> T.readVal iprot (T.T_STRUCT typemap_Message)
decode_Message :: (T.Protocol p, T.Transport t) => p t -> LBS.ByteString -> Message
decode_Message iprot bs = to_Message $ T.deserializeVal iprot (T.T_STRUCT typemap_Message) bs
typemap_Message :: T.TypeMap
typemap_Message = Map.fromList [(1,("msg",T.T_STRING))]
default_Message :: Message
default_Message = Message{
  message_msg = "default message"}
