content: {-# OPTIONS_GHC -Wno-orphans #-}
  
  module GetTested.Types where
  
  import Data.Aeson
  import Data.Text (Text)
  import Data.Text qualified as Text
  import Data.Text.Display
  import Data.Vector (Vector)
  import Data.Vector qualified as Vector
  import Distribution.Compiler
  import Distribution.Parsec (simpleParsec)
  import Distribution.Pretty qualified as Pretty
  import Distribution.Types.Version
  import Distribution.Types.VersionRange
  import GHC.Generics (Generic)
  
  data ProcessingError
    = CabalFileNotFound FilePath
    | CabalFileCouldNotBeParsed FilePath
    | NoCompilerVersionsFound FilePath
    | IncompatibleOptions Text Text
    deriving stock (Eq, Ord, Show)
    deriving
      (Display)
      via ShowInstance ProcessingError
  
  data RunnerOS
    = Ubuntu
    | Windows
    | MacOS
    deriving stock (Eq, Ord, Show)
  
  instance Display RunnerOS where
    displayBuilder Ubuntu = "ubuntu"
    displayBuilder Windows = "windows"
    displayBuilder MacOS = "macos"
  
  instance ToJSON CompilerFlavor where
    toJSON = toJSON . Pretty.prettyShow
  
  instance FromJSON CompilerFlavor where
    parseJSON = withText "Compiler Flavor" $ \s ->
      maybe (fail "Invalid compiler flavor") pure (simpleParsec $ Text.unpack s)
  
  instance Display CompilerFlavor where
    displayBuilder = displayBuilder . Pretty.prettyShow
  
  instance Display VersionRange where
    displayBuilder = displayBuilder . Pretty.prettyShow
  
  instance ToJSON Version where
    toJSON = toJSON . Pretty.prettyShow
  
  instance FromJSON VersionRange where
    parseJSON = withText "Version Range" $ \s ->
      maybe (fail "Invalid version range") pure (simpleParsec $ Text.unpack s)
  
  data ActionMatrix = ActionMatrix
    { include :: Vector PlatformAndVersion
    }
    deriving stock (Eq, Ord, Generic)
    deriving anyclass (ToJSON)
  
  data PlatformAndVersion = PlatformAndVersion
    { os :: Text
    , ghc :: Version
    , oldest :: Bool
    , newest :: Bool
    }
    deriving stock (Eq, Ord, Generic)
    deriving anyclass (ToJSON)
  
  osList :: Vector Text
  osList =
    Vector.fromList
      [ "ubuntu-latest"
      , "macos-latest"
      , "windows-latest"
      ]
  