module Network.AWS.Data.Internal.Numeric where
import Control.Applicative
import Control.Lens.TH
import Control.Monad
import Data.Aeson.Types
import Network.AWS.Data.Internal.ByteString
import Network.AWS.Data.Internal.Query
import Network.AWS.Data.Internal.Text
import Network.AWS.Data.Internal.XML
import Numeric.Natural
newtype Nat = Nat { unNat :: Natural }
deriving
( Eq
, Ord
, Show
, Enum
, Num
, Real
, Integral
, Whole
, ToByteString
, FromText
, ToText
, FromXML
, ToXML
, ToQuery
)
instance FromJSON Nat where
parseJSON = parseJSON >=> \n ->
if n < 0
then fail $ "Cannot convert negative number to Natural: " ++ show n
else pure $ Nat (fromInteger n)
instance ToJSON Nat where
toJSON = String . toText . unNat
makePrisms ''Nat