module Test.Marionette.Orientation where

import Data.Aeson.Types
import GHC.Generics (Generic)
import Prelude

data Orientation = Portrait | Landscape
    deriving stock (Orientation -> Orientation -> Bool
(Orientation -> Orientation -> Bool)
-> (Orientation -> Orientation -> Bool) -> Eq Orientation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Orientation -> Orientation -> Bool
== :: Orientation -> Orientation -> Bool
$c/= :: Orientation -> Orientation -> Bool
/= :: Orientation -> Orientation -> Bool
Eq, Int -> Orientation -> ShowS
[Orientation] -> ShowS
Orientation -> String
(Int -> Orientation -> ShowS)
-> (Orientation -> String)
-> ([Orientation] -> ShowS)
-> Show Orientation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Orientation -> ShowS
showsPrec :: Int -> Orientation -> ShowS
$cshow :: Orientation -> String
show :: Orientation -> String
$cshowList :: [Orientation] -> ShowS
showList :: [Orientation] -> ShowS
Show, (forall x. Orientation -> Rep Orientation x)
-> (forall x. Rep Orientation x -> Orientation)
-> Generic Orientation
forall x. Rep Orientation x -> Orientation
forall x. Orientation -> Rep Orientation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Orientation -> Rep Orientation x
from :: forall x. Orientation -> Rep Orientation x
$cto :: forall x. Rep Orientation x -> Orientation
to :: forall x. Rep Orientation x -> Orientation
Generic)

instance ToJSON Orientation where
    toJSON :: Orientation -> Value
toJSON Orientation
Portrait = Text -> Value
String Text
"portrait"
    toJSON Orientation
Landscape = Text -> Value
String Text
"landscape"

instance FromJSON Orientation where
    parseJSON :: Value -> Parser Orientation
parseJSON = String
-> (Text -> Parser Orientation) -> Value -> Parser Orientation
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"Orientation" \case
        Text
"portrait" -> Orientation -> Parser Orientation
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Orientation
Portrait
        Text
"landscape" -> Orientation -> Parser Orientation
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Orientation
Landscape
        Text
other -> String -> Parser Orientation
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Orientation) -> String -> Parser Orientation
forall a b. (a -> b) -> a -> b
$ String
"Unknown orientation: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. Show a => a -> String
show Text
other