{-# LANGUAGE TemplateHaskell #-}
module Persistence.Schema.EvaluationStateType where

import Data.List (isPrefixOf)
import Database.Persist.TH

data EvaluationStateType = NotYetEnqueued
                         | Enqueued
                         | Processing
                         | FinishedSuccessfully
                         | FinishedUnsuccessfully
                           deriving (EvaluationStateType -> EvaluationStateType -> Bool
(EvaluationStateType -> EvaluationStateType -> Bool)
-> (EvaluationStateType -> EvaluationStateType -> Bool)
-> Eq EvaluationStateType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EvaluationStateType -> EvaluationStateType -> Bool
$c/= :: EvaluationStateType -> EvaluationStateType -> Bool
== :: EvaluationStateType -> EvaluationStateType -> Bool
$c== :: EvaluationStateType -> EvaluationStateType -> Bool
Eq)

instance Show EvaluationStateType where
  show :: EvaluationStateType -> String
show NotYetEnqueued = "not_yet_enqueued"
  show Enqueued = "enqueued"
  show Processing = "processing"
  show FinishedSuccessfully = "finished_successfully"
  show FinishedUnsuccessfully = "finished_unsuccessfully"

instance Read EvaluationStateType where
  readsPrec :: Int -> ReadS EvaluationStateType
readsPrec _ input :: String
input
    | EvaluationStateType -> String
forall a. Show a => a -> String
show EvaluationStateType
NotYetEnqueued String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` String
input = [(EvaluationStateType
NotYetEnqueued, Int -> ShowS
forall a. Int -> [a] -> [a]
drop (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (String -> Int) -> String -> Int
forall a b. (a -> b) -> a -> b
$ EvaluationStateType -> String
forall a. Show a => a -> String
show EvaluationStateType
NotYetEnqueued) String
input)]
    | EvaluationStateType -> String
forall a. Show a => a -> String
show EvaluationStateType
Enqueued String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` String
input = [(EvaluationStateType
Enqueued, Int -> ShowS
forall a. Int -> [a] -> [a]
drop (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (String -> Int) -> String -> Int
forall a b. (a -> b) -> a -> b
$ EvaluationStateType -> String
forall a. Show a => a -> String
show EvaluationStateType
Enqueued) String
input)]
    | EvaluationStateType -> String
forall a. Show a => a -> String
show EvaluationStateType
Processing String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` String
input = [(EvaluationStateType
Processing, Int -> ShowS
forall a. Int -> [a] -> [a]
drop (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (String -> Int) -> String -> Int
forall a b. (a -> b) -> a -> b
$ EvaluationStateType -> String
forall a. Show a => a -> String
show EvaluationStateType
Processing) String
input)]
    | EvaluationStateType -> String
forall a. Show a => a -> String
show EvaluationStateType
FinishedSuccessfully String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` String
input = [(EvaluationStateType
FinishedSuccessfully, Int -> ShowS
forall a. Int -> [a] -> [a]
drop (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (String -> Int) -> String -> Int
forall a b. (a -> b) -> a -> b
$ EvaluationStateType -> String
forall a. Show a => a -> String
show EvaluationStateType
FinishedSuccessfully) String
input)]
    | EvaluationStateType -> String
forall a. Show a => a -> String
show EvaluationStateType
FinishedUnsuccessfully String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` String
input = [(EvaluationStateType
FinishedUnsuccessfully, Int -> ShowS
forall a. Int -> [a] -> [a]
drop (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (String -> Int) -> String -> Int
forall a b. (a -> b) -> a -> b
$ EvaluationStateType -> String
forall a. Show a => a -> String
show EvaluationStateType
FinishedUnsuccessfully) String
input)]
    | Bool
otherwise = []

derivePersistField "EvaluationStateType"