{-# OPTIONS_GHC -Wno-orphans #-}{-# LANGUAGE DataKinds #-}{-# LANGUAGE FlexibleContexts #-}{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE TypeFamilies #-}{-|Module : GHCup.Types.JSON.VersionsDescription : GHCup Version JSON types/instancesCopyright : (c) Julian Ospald, 2020License : LGPL-3.0Maintainer : hasufell@hasufell.deStability : experimentalPortability : portable-}module GHCup.Types.JSON.Versions whereimport Data.Aeson hiding ( Key )import Data.Aeson.Types hiding ( Key )import Data.Versionsimport qualified Data.Text as Tinstance ToJSON Versioning where toJSON = toJSON . prettyVinstance FromJSON Versioning where parseJSON = withText "Versioning" $ \t -> case versioning t of Right x -> pure x Left e -> fail $ "Failure in TargetVersion (FromJSON)" <> show einstance ToJSONKey Versioning where toJSONKey = toJSONKeyText $ \x -> prettyV xinstance FromJSONKey Versioning where fromJSONKey = FromJSONKeyTextParser $ \t -> case versioning t of Right x -> pure x Left e -> fail $ "Failure in Versioning (FromJSONKey)" <> show einstance ToJSONKey (Maybe Versioning) where toJSONKey = toJSONKeyText $ \case Just x -> prettyV x Nothing -> T.pack "unknown_versioning"instance FromJSONKey (Maybe Versioning) where fromJSONKey = FromJSONKeyTextParser $ \t -> if t == T.pack "unknown_versioning" then pure Nothing else just t where just t = case versioning t of Right x -> pure $ Just x Left e -> fail $ "Failure in (Maybe Versioning) (FromJSONKey)" <> show einstance ToJSONKey (Maybe Version) where toJSONKey = toJSONKeyText $ \case Just x -> prettyVer x Nothing -> T.pack "unknown_version"instance FromJSONKey (Maybe Version) where fromJSONKey = FromJSONKeyTextParser $ \t -> if t == T.pack "unknown_version" then pure Nothing else just t where just t = case version t of Right x -> pure $ Just x Left e -> fail $ "Failure in (Maybe Version) (FromJSONKey)" <> show einstance ToJSON Version where toJSON = toJSON . prettyVerinstance FromJSON Version where parseJSON = withText "Version" $ \t -> case version t of Right x -> pure x Left e -> fail $ "Failure in Version (FromJSON)" <> show einstance ToJSONKey Version where toJSONKey = toJSONKeyText $ \x -> prettyVer xinstance FromJSONKey Version where fromJSONKey = FromJSONKeyTextParser $ \t -> case version t of Right x -> pure x Left e -> fail $ "Failure in Version (FromJSONKey)" <> show einstance ToJSON PVP where toJSON = toJSON . prettyPVPinstance FromJSON PVP where parseJSON = withText "PVP" $ \t -> case pvp t of Right x -> pure x Left e -> fail $ "Failure in PVP (FromJSON)" <> show e