module TD.Data.ClosedVectorPath
  (ClosedVectorPath(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.VectorPathCommand as VectorPathCommand

data ClosedVectorPath
  = ClosedVectorPath -- ^ Represents a closed vector path. The path begins at the end point of the last command
    { ClosedVectorPath -> Maybe [VectorPathCommand]
commands :: Maybe [VectorPathCommand.VectorPathCommand] -- ^ List of vector path commands
    }
  deriving (ClosedVectorPath -> ClosedVectorPath -> Bool
(ClosedVectorPath -> ClosedVectorPath -> Bool)
-> (ClosedVectorPath -> ClosedVectorPath -> Bool)
-> Eq ClosedVectorPath
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClosedVectorPath -> ClosedVectorPath -> Bool
== :: ClosedVectorPath -> ClosedVectorPath -> Bool
$c/= :: ClosedVectorPath -> ClosedVectorPath -> Bool
/= :: ClosedVectorPath -> ClosedVectorPath -> Bool
Eq, Int -> ClosedVectorPath -> ShowS
[ClosedVectorPath] -> ShowS
ClosedVectorPath -> String
(Int -> ClosedVectorPath -> ShowS)
-> (ClosedVectorPath -> String)
-> ([ClosedVectorPath] -> ShowS)
-> Show ClosedVectorPath
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClosedVectorPath -> ShowS
showsPrec :: Int -> ClosedVectorPath -> ShowS
$cshow :: ClosedVectorPath -> String
show :: ClosedVectorPath -> String
$cshowList :: [ClosedVectorPath] -> ShowS
showList :: [ClosedVectorPath] -> ShowS
Show)

instance I.ShortShow ClosedVectorPath where
  shortShow :: ClosedVectorPath -> String
shortShow ClosedVectorPath
    { commands :: ClosedVectorPath -> Maybe [VectorPathCommand]
commands = Maybe [VectorPathCommand]
commands_
    }
      = String
"ClosedVectorPath"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"commands" String -> Maybe [VectorPathCommand] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [VectorPathCommand]
commands_
        ]

instance AT.FromJSON ClosedVectorPath where
  parseJSON :: Value -> Parser ClosedVectorPath
parseJSON v :: Value
v@(AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"closedVectorPath" -> Value -> Parser ClosedVectorPath
parseClosedVectorPath Value
v
      String
_                  -> Parser ClosedVectorPath
forall a. Monoid a => a
mempty
    
    where
      parseClosedVectorPath :: A.Value -> AT.Parser ClosedVectorPath
      parseClosedVectorPath :: Value -> Parser ClosedVectorPath
parseClosedVectorPath = String
-> (Object -> Parser ClosedVectorPath)
-> Value
-> Parser ClosedVectorPath
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ClosedVectorPath" ((Object -> Parser ClosedVectorPath)
 -> Value -> Parser ClosedVectorPath)
-> (Object -> Parser ClosedVectorPath)
-> Value
-> Parser ClosedVectorPath
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [VectorPathCommand]
commands_ <- Object
o Object -> Key -> Parser (Maybe [VectorPathCommand])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"commands"
        ClosedVectorPath -> Parser ClosedVectorPath
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ClosedVectorPath -> Parser ClosedVectorPath)
-> ClosedVectorPath -> Parser ClosedVectorPath
forall a b. (a -> b) -> a -> b
$ ClosedVectorPath
          { commands :: Maybe [VectorPathCommand]
commands = Maybe [VectorPathCommand]
commands_
          }
  parseJSON Value
_ = Parser ClosedVectorPath
forall a. Monoid a => a
mempty