{-# LANGUAGE RecordWildCards #-}

module Potato.Flow.Preview where

import           Relude

import Potato.Flow.Llama


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

instance NFData Shepard

-- TODO use this to identify preview chains in the future
-- TODO also use to identify handlers
data Shift = Shift Int deriving (Shift -> Shift -> Bool
(Shift -> Shift -> Bool) -> (Shift -> Shift -> Bool) -> Eq Shift
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Shift -> Shift -> Bool
== :: Shift -> Shift -> Bool
$c/= :: Shift -> Shift -> Bool
/= :: Shift -> Shift -> Bool
Eq, Int -> Shift -> ShowS
[Shift] -> ShowS
Shift -> String
(Int -> Shift -> ShowS)
-> (Shift -> String) -> ([Shift] -> ShowS) -> Show Shift
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Shift -> ShowS
showsPrec :: Int -> Shift -> ShowS
$cshow :: Shift -> String
show :: Shift -> String
$cshowList :: [Shift] -> ShowS
showList :: [Shift] -> ShowS
Show, (forall x. Shift -> Rep Shift x)
-> (forall x. Rep Shift x -> Shift) -> Generic Shift
forall x. Rep Shift x -> Shift
forall x. Shift -> Rep Shift x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Shift -> Rep Shift x
from :: forall x. Shift -> Rep Shift x
$cto :: forall x. Rep Shift x -> Shift
to :: forall x. Rep Shift x -> Shift
Generic)

instance NFData Shift

dummyShepard :: Shepard
dummyShepard :: Shepard
dummyShepard = Int -> Shepard
Shepard Int
0

dummyShift :: Shift
dummyShift :: Shift
dummyShift = Int -> Shift
Shift Int
0


-- TODO add 
-- PO_StartAndCommit and PO_ContinueAndCommit are equivalent to doing a PO_Start or PO_Continue followed by a Preview_Commit, just for convenience
-- NOTE that PO_Start/PO_Continue will commit when another a preview comes in from the local user, the main reason you want to commit is to ensure the preview gets saved
-- NOTE that PO_CommitAndStart is identitacl to PO_Start but also asserts that there is a local preview
data PreviewOperation = 
  PO_Start 
  | PO_CommitAndStart 
  | PO_StartAndCommit 
  | PO_Continue 
  | PO_ContinueAndCommit 
  deriving (PreviewOperation -> PreviewOperation -> Bool
(PreviewOperation -> PreviewOperation -> Bool)
-> (PreviewOperation -> PreviewOperation -> Bool)
-> Eq PreviewOperation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PreviewOperation -> PreviewOperation -> Bool
== :: PreviewOperation -> PreviewOperation -> Bool
$c/= :: PreviewOperation -> PreviewOperation -> Bool
/= :: PreviewOperation -> PreviewOperation -> Bool
Eq, Int -> PreviewOperation -> ShowS
[PreviewOperation] -> ShowS
PreviewOperation -> String
(Int -> PreviewOperation -> ShowS)
-> (PreviewOperation -> String)
-> ([PreviewOperation] -> ShowS)
-> Show PreviewOperation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PreviewOperation -> ShowS
showsPrec :: Int -> PreviewOperation -> ShowS
$cshow :: PreviewOperation -> String
show :: PreviewOperation -> String
$cshowList :: [PreviewOperation] -> ShowS
showList :: [PreviewOperation] -> ShowS
Show, (forall x. PreviewOperation -> Rep PreviewOperation x)
-> (forall x. Rep PreviewOperation x -> PreviewOperation)
-> Generic PreviewOperation
forall x. Rep PreviewOperation x -> PreviewOperation
forall x. PreviewOperation -> Rep PreviewOperation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PreviewOperation -> Rep PreviewOperation x
from :: forall x. PreviewOperation -> Rep PreviewOperation x
$cto :: forall x. Rep PreviewOperation x -> PreviewOperation
to :: forall x. Rep PreviewOperation x -> PreviewOperation
Generic)

data Preview = 
  -- apply a preview operation
  Preview PreviewOperation Llama 
  -- commit the last operation
  | Preview_Commit
  -- same as above but does not assert that there is a local preview
  | Preview_MaybeCommit 
  -- cancel the preview 
  | Preview_Cancel 
  deriving (Int -> Preview -> ShowS
[Preview] -> ShowS
Preview -> String
(Int -> Preview -> ShowS)
-> (Preview -> String) -> ([Preview] -> ShowS) -> Show Preview
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Preview -> ShowS
showsPrec :: Int -> Preview -> ShowS
$cshow :: Preview -> String
show :: Preview -> String
$cshowList :: [Preview] -> ShowS
showList :: [Preview] -> ShowS
Show, (forall x. Preview -> Rep Preview x)
-> (forall x. Rep Preview x -> Preview) -> Generic Preview
forall x. Rep Preview x -> Preview
forall x. Preview -> Rep Preview x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Preview -> Rep Preview x
from :: forall x. Preview -> Rep Preview x
$cto :: forall x. Rep Preview x -> Preview
to :: forall x. Rep Preview x -> Preview
Generic)

previewOperation_fromUndoFirst :: Bool -> PreviewOperation
previewOperation_fromUndoFirst :: Bool -> PreviewOperation
previewOperation_fromUndoFirst Bool
undoFirst = case Bool
undoFirst of
  Bool
True -> PreviewOperation
PO_Continue
  Bool
False -> PreviewOperation
PO_Start

previewOperation_toUndoFirst :: PreviewOperation -> Bool
previewOperation_toUndoFirst :: PreviewOperation -> Bool
previewOperation_toUndoFirst PreviewOperation
po = case PreviewOperation
po of
  PreviewOperation
PO_Start -> Bool
False
  PreviewOperation
PO_Continue -> Bool
True
  PreviewOperation
PO_StartAndCommit -> Bool
False
  PreviewOperation
PO_ContinueAndCommit -> Bool
True