module U.Codebase.Sqlite.TempEntityType where

import Unison.Sqlite (FromField (..), SQLData (SQLInteger), ToField (..))

-- | Don't reorder these, they are part of the database,
--  and the ToField and FromField implementation currently
--  depends on the derived Enum implementation.
data TempEntityType
  = TermComponentType -- 0
  | DeclComponentType -- 1
  | NamespaceType -- 2
  | PatchType -- 3
  | CausalType -- 4
  deriving (TempEntityType -> TempEntityType -> Bool
(TempEntityType -> TempEntityType -> Bool)
-> (TempEntityType -> TempEntityType -> Bool) -> Eq TempEntityType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TempEntityType -> TempEntityType -> Bool
== :: TempEntityType -> TempEntityType -> Bool
$c/= :: TempEntityType -> TempEntityType -> Bool
/= :: TempEntityType -> TempEntityType -> Bool
Eq, Eq TempEntityType
Eq TempEntityType =>
(TempEntityType -> TempEntityType -> Ordering)
-> (TempEntityType -> TempEntityType -> Bool)
-> (TempEntityType -> TempEntityType -> Bool)
-> (TempEntityType -> TempEntityType -> Bool)
-> (TempEntityType -> TempEntityType -> Bool)
-> (TempEntityType -> TempEntityType -> TempEntityType)
-> (TempEntityType -> TempEntityType -> TempEntityType)
-> Ord TempEntityType
TempEntityType -> TempEntityType -> Bool
TempEntityType -> TempEntityType -> Ordering
TempEntityType -> TempEntityType -> TempEntityType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TempEntityType -> TempEntityType -> Ordering
compare :: TempEntityType -> TempEntityType -> Ordering
$c< :: TempEntityType -> TempEntityType -> Bool
< :: TempEntityType -> TempEntityType -> Bool
$c<= :: TempEntityType -> TempEntityType -> Bool
<= :: TempEntityType -> TempEntityType -> Bool
$c> :: TempEntityType -> TempEntityType -> Bool
> :: TempEntityType -> TempEntityType -> Bool
$c>= :: TempEntityType -> TempEntityType -> Bool
>= :: TempEntityType -> TempEntityType -> Bool
$cmax :: TempEntityType -> TempEntityType -> TempEntityType
max :: TempEntityType -> TempEntityType -> TempEntityType
$cmin :: TempEntityType -> TempEntityType -> TempEntityType
min :: TempEntityType -> TempEntityType -> TempEntityType
Ord, Int -> TempEntityType -> ShowS
[TempEntityType] -> ShowS
TempEntityType -> String
(Int -> TempEntityType -> ShowS)
-> (TempEntityType -> String)
-> ([TempEntityType] -> ShowS)
-> Show TempEntityType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TempEntityType -> ShowS
showsPrec :: Int -> TempEntityType -> ShowS
$cshow :: TempEntityType -> String
show :: TempEntityType -> String
$cshowList :: [TempEntityType] -> ShowS
showList :: [TempEntityType] -> ShowS
Show, Int -> TempEntityType
TempEntityType -> Int
TempEntityType -> [TempEntityType]
TempEntityType -> TempEntityType
TempEntityType -> TempEntityType -> [TempEntityType]
TempEntityType
-> TempEntityType -> TempEntityType -> [TempEntityType]
(TempEntityType -> TempEntityType)
-> (TempEntityType -> TempEntityType)
-> (Int -> TempEntityType)
-> (TempEntityType -> Int)
-> (TempEntityType -> [TempEntityType])
-> (TempEntityType -> TempEntityType -> [TempEntityType])
-> (TempEntityType -> TempEntityType -> [TempEntityType])
-> (TempEntityType
    -> TempEntityType -> TempEntityType -> [TempEntityType])
-> Enum TempEntityType
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: TempEntityType -> TempEntityType
succ :: TempEntityType -> TempEntityType
$cpred :: TempEntityType -> TempEntityType
pred :: TempEntityType -> TempEntityType
$ctoEnum :: Int -> TempEntityType
toEnum :: Int -> TempEntityType
$cfromEnum :: TempEntityType -> Int
fromEnum :: TempEntityType -> Int
$cenumFrom :: TempEntityType -> [TempEntityType]
enumFrom :: TempEntityType -> [TempEntityType]
$cenumFromThen :: TempEntityType -> TempEntityType -> [TempEntityType]
enumFromThen :: TempEntityType -> TempEntityType -> [TempEntityType]
$cenumFromTo :: TempEntityType -> TempEntityType -> [TempEntityType]
enumFromTo :: TempEntityType -> TempEntityType -> [TempEntityType]
$cenumFromThenTo :: TempEntityType
-> TempEntityType -> TempEntityType -> [TempEntityType]
enumFromThenTo :: TempEntityType
-> TempEntityType -> TempEntityType -> [TempEntityType]
Enum)

instance ToField TempEntityType where
  toField :: TempEntityType -> SQLData
toField = Int64 -> SQLData
SQLInteger (Int64 -> SQLData)
-> (TempEntityType -> Int64) -> TempEntityType -> SQLData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int64)
-> (TempEntityType -> Int) -> TempEntityType -> Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TempEntityType -> Int
forall a. Enum a => a -> Int
fromEnum

instance FromField TempEntityType where
  fromField :: FieldParser TempEntityType
fromField = (Int -> TempEntityType) -> Ok Int -> Ok TempEntityType
forall a b. (a -> b) -> Ok a -> Ok b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> TempEntityType
forall a. Enum a => Int -> a
toEnum (Ok Int -> Ok TempEntityType)
-> (Field -> Ok Int) -> FieldParser TempEntityType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Field -> Ok Int
forall a. FromField a => FieldParser a
fromField