module Network.IPFS.Stat.Error (OverflowDetected (..)) where

import qualified RIO.Text             as Text

import           Network.IPFS.Prelude

data OverflowDetected = OverflowDetected
  deriving (OverflowDetected -> OverflowDetected -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OverflowDetected -> OverflowDetected -> Bool
$c/= :: OverflowDetected -> OverflowDetected -> Bool
== :: OverflowDetected -> OverflowDetected -> Bool
$c== :: OverflowDetected -> OverflowDetected -> Bool
Eq, Int -> OverflowDetected -> ShowS
[OverflowDetected] -> ShowS
OverflowDetected -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OverflowDetected] -> ShowS
$cshowList :: [OverflowDetected] -> ShowS
show :: OverflowDetected -> String
$cshow :: OverflowDetected -> String
showsPrec :: Int -> OverflowDetected -> ShowS
$cshowsPrec :: Int -> OverflowDetected -> ShowS
Show)

instance Display OverflowDetected where
  display :: OverflowDetected -> Utf8Builder
display OverflowDetected
OverflowDetected = Utf8Builder
"OverflowDetected"

instance ToJSON OverflowDetected where
  toJSON :: OverflowDetected -> Value
toJSON OverflowDetected
OverflowDetected = Text -> Value
String Text
"OverflowDetected"

instance FromJSON OverflowDetected where
  parseJSON :: Value -> Parser OverflowDetected
parseJSON =
    forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"OverflowDetected" \Text
txt ->
      if Text
"-" Text -> Text -> Bool
`Text.isPrefixOf` Text
txt
        then forall (m :: * -> *) a. Monad m => a -> m a
return OverflowDetected
OverflowDetected
        else forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Not an overflow"