summaryrefslogtreecommitdiff
path: root/src/Conftrack/Value.hs
blob: c5768cc93a610d2b274ccf95f2ab1d3cc060345f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE AllowAmbiguousTypes #-}

module Conftrack.Value (Value(..), ConfigError(..), Key(..), ConfigValue(..), Origin(..)) where

import Data.Text(Text)
import Data.List.NonEmpty (NonEmpty)

data Value =
  ConfigText Text
  | ConfigInteger Integer
  | ConfigOther Text Text
  deriving Show

newtype Key = Key (NonEmpty Text)
  deriving newtype (Eq, Ord, Show)

data ConfigError =
  ParseError
  | NotPresent
  deriving Show

class ConfigValue a where
  fromConfig :: Value -> Either ConfigError a

data Origin = Origin Key Text
  deriving Show

instance ConfigValue Text where
  fromConfig (ConfigText a) = Right a
  fromConfig _ = Left ParseError

instance ConfigValue Integer where
  fromConfig (ConfigInteger a) = Right a
  fromConfig _ = Left ParseError