{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}

module Stack.Types.VersionedDownloadInfo
  ( VersionedDownloadInfo (..)
  ) where

import           Data.Aeson.Types ( FromJSON (..) )
import           Data.Aeson.WarningParser
                   ( WithJSONWarnings (..), (..:), withObjectWarnings )
import           Stack.Prelude
import           Stack.Types.DownloadInfo
                   ( DownloadInfo, parseDownloadInfoFromObject )

data VersionedDownloadInfo = VersionedDownloadInfo
  { VersionedDownloadInfo -> Version
vdiVersion :: Version
  , VersionedDownloadInfo -> DownloadInfo
vdiDownloadInfo :: DownloadInfo
  }
  deriving Int -> VersionedDownloadInfo -> ShowS
[VersionedDownloadInfo] -> ShowS
VersionedDownloadInfo -> String
(Int -> VersionedDownloadInfo -> ShowS)
-> (VersionedDownloadInfo -> String)
-> ([VersionedDownloadInfo] -> ShowS)
-> Show VersionedDownloadInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VersionedDownloadInfo -> ShowS
showsPrec :: Int -> VersionedDownloadInfo -> ShowS
$cshow :: VersionedDownloadInfo -> String
show :: VersionedDownloadInfo -> String
$cshowList :: [VersionedDownloadInfo] -> ShowS
showList :: [VersionedDownloadInfo] -> ShowS
Show

instance FromJSON (WithJSONWarnings VersionedDownloadInfo) where
  parseJSON :: Value -> Parser (WithJSONWarnings VersionedDownloadInfo)
parseJSON = String
-> (Object -> WarningParser VersionedDownloadInfo)
-> Value
-> Parser (WithJSONWarnings VersionedDownloadInfo)
forall a.
String
-> (Object -> WarningParser a)
-> Value
-> Parser (WithJSONWarnings a)
withObjectWarnings String
"VersionedDownloadInfo" ((Object -> WarningParser VersionedDownloadInfo)
 -> Value -> Parser (WithJSONWarnings VersionedDownloadInfo))
-> (Object -> WarningParser VersionedDownloadInfo)
-> Value
-> Parser (WithJSONWarnings VersionedDownloadInfo)
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    CabalString Version
version <- Object
o Object -> Text -> WarningParser (CabalString Version)
forall a. FromJSON a => Object -> Text -> WarningParser a
..: Text
"version"
    DownloadInfo
downloadInfo <- Object -> WarningParser DownloadInfo
parseDownloadInfoFromObject Object
o
    VersionedDownloadInfo -> WarningParser VersionedDownloadInfo
forall a. a -> WriterT WarningParserMonoid Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure VersionedDownloadInfo
      { vdiVersion :: Version
vdiVersion = Version
version
      , vdiDownloadInfo :: DownloadInfo
vdiDownloadInfo = DownloadInfo
downloadInfo
      }