module Debugger.API
  ( API
  , ServerAPI

  , LayerName
  , Drawing(Drawing)
  , Drawings

  , defaultHost
  , defaultPort
  ) where

import           Servant.API
import           GHC.Generics
import           Data.Aeson
import           Data.Text (Text)
import           Miso.Types
import qualified Data.Aeson as Aeson
import           Data.Coerce
import           Data.Map (Map)
import           Data.Sequence (Seq)

--------------------------------------------------------------------------------


type LayerName = String

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

instance Aeson.ToJSON Drawing where
instance Aeson.FromJSON Drawing where


type Drawings = Map LayerName (Seq (String, Drawing))

type API =    "drawing"    :> Get '[ JSON ] Drawings
         :<|> "drawLayer"  :> ReqBody '[ JSON ] (LayerName, String, Drawing) :> Put '[JSON] ()
         :<|> "clearLayer" :> ReqBody '[ PlainText ] LayerName               :> Put '[JSON] ()
         :<|> "clear"      :> Put '[JSON] ()

type ServerAPI = "pub"        :> Raw
         :<|> API

--------------------------------------------------------------------------------

defaultPort :: Int -- Port
defaultPort :: Int
defaultPort = Int
8000

defaultHost :: String
defaultHost :: String
defaultHost = String
"localhost"




--------------------------------------------------------------------------------

-- deriving instance (Generic action, Generic model) => Generic (View context props model action)
-- deriving instance (Generic parent, Generic model, Generic action
--                   ) => Generic (Component parent model action)
-- instance (Generic parent) => Generic (SomeComponent parent) where



-- data ViewJSON =

-- instance (ToJSON model, ToJSON action) => ToJSON (View context props model action) where
--    toEncoding =


--      genericToEncoding defaultOptions