{-# LANGUAGE NoImplicitPrelude #-}

module Codec.QRCode.Data.Version
  ( Version
  , unVersion
  , VersionRange(..)
  , versionsInRangeLimitedBy
  ) where

import           Codec.QRCode.Base

newtype Version
  = Version
  { Version -> Int
unVersion_ :: Int
  }

unVersion :: Version -> Int
{-# INLINE unVersion #-}
unVersion :: Version -> Int
unVersion = Version -> Int
unVersion_

data VersionRange
  = Version1to9
  | Version10to26
  | Version27to40
  deriving (VersionRange
VersionRange -> VersionRange -> Bounded VersionRange
forall a. a -> a -> Bounded a
maxBound :: VersionRange
$cmaxBound :: VersionRange
minBound :: VersionRange
$cminBound :: VersionRange
Bounded, Int -> VersionRange
VersionRange -> Int
VersionRange -> [VersionRange]
VersionRange -> VersionRange
VersionRange -> VersionRange -> [VersionRange]
VersionRange -> VersionRange -> VersionRange -> [VersionRange]
(VersionRange -> VersionRange)
-> (VersionRange -> VersionRange)
-> (Int -> VersionRange)
-> (VersionRange -> Int)
-> (VersionRange -> [VersionRange])
-> (VersionRange -> VersionRange -> [VersionRange])
-> (VersionRange -> VersionRange -> [VersionRange])
-> (VersionRange -> VersionRange -> VersionRange -> [VersionRange])
-> Enum VersionRange
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: VersionRange -> VersionRange -> VersionRange -> [VersionRange]
$cenumFromThenTo :: VersionRange -> VersionRange -> VersionRange -> [VersionRange]
enumFromTo :: VersionRange -> VersionRange -> [VersionRange]
$cenumFromTo :: VersionRange -> VersionRange -> [VersionRange]
enumFromThen :: VersionRange -> VersionRange -> [VersionRange]
$cenumFromThen :: VersionRange -> VersionRange -> [VersionRange]
enumFrom :: VersionRange -> [VersionRange]
$cenumFrom :: VersionRange -> [VersionRange]
fromEnum :: VersionRange -> Int
$cfromEnum :: VersionRange -> Int
toEnum :: Int -> VersionRange
$ctoEnum :: Int -> VersionRange
pred :: VersionRange -> VersionRange
$cpred :: VersionRange -> VersionRange
succ :: VersionRange -> VersionRange
$csucc :: VersionRange -> VersionRange
Enum, VersionRange -> VersionRange -> Bool
(VersionRange -> VersionRange -> Bool)
-> (VersionRange -> VersionRange -> Bool) -> Eq VersionRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VersionRange -> VersionRange -> Bool
$c/= :: VersionRange -> VersionRange -> Bool
== :: VersionRange -> VersionRange -> Bool
$c== :: VersionRange -> VersionRange -> Bool
Eq)

versionsInRangeLimitedBy :: VersionRange -> Int -> Int -> [Version]
versionsInRangeLimitedBy :: VersionRange -> Int -> Int -> [Version]
versionsInRangeLimitedBy VersionRange
Version1to9   Int
start Int
end = (Int -> Version) -> [Int] -> [Version]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Version
Version [Int
start Int -> Int -> Int
forall a. Ord a => a -> a -> a
`max`  Int
1 .. Int
end Int -> Int -> Int
forall a. Ord a => a -> a -> a
`min`  Int
9]
versionsInRangeLimitedBy VersionRange
Version10to26 Int
start Int
end = (Int -> Version) -> [Int] -> [Version]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Version
Version [Int
start Int -> Int -> Int
forall a. Ord a => a -> a -> a
`max` Int
10 .. Int
end Int -> Int -> Int
forall a. Ord a => a -> a -> a
`min` Int
26]
versionsInRangeLimitedBy VersionRange
Version27to40 Int
start Int
end = (Int -> Version) -> [Int] -> [Version]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Version
Version [Int
start Int -> Int -> Int
forall a. Ord a => a -> a -> a
`max` Int
27 .. Int
end Int -> Int -> Int
forall a. Ord a => a -> a -> a
`min` Int
40]