{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}

module Navi.Data.CommandResult
  ( CommandResult (..),
  )
where

import Navi.Data.PollInterval (PollInterval)
import Navi.Prelude

-- The result of running a custom command.
data CommandResult = MkCommandResult
  { -- | Potential output text.
    CommandResult -> Maybe Text
output :: Maybe Text,
    -- | Potential poll interval.
    CommandResult -> Maybe PollInterval
pollInterval :: Maybe PollInterval,
    -- | The actual result, corresponding to possible triggers.
    CommandResult -> Text
result :: Text
  }
  deriving stock (Int -> CommandResult -> ShowS
[CommandResult] -> ShowS
CommandResult -> String
(Int -> CommandResult -> ShowS)
-> (CommandResult -> String)
-> ([CommandResult] -> ShowS)
-> Show CommandResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CommandResult -> ShowS
showsPrec :: Int -> CommandResult -> ShowS
$cshow :: CommandResult -> String
show :: CommandResult -> String
$cshowList :: [CommandResult] -> ShowS
showList :: [CommandResult] -> ShowS
Show)

makeFieldLabelsNoPrefix ''CommandResult

instance Eq CommandResult where
  CommandResult
x == :: CommandResult -> CommandResult -> Bool
== CommandResult
y = CommandResult -> Text
toResult CommandResult
x Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== CommandResult -> Text
toResult CommandResult
y

instance Ord CommandResult where
  CommandResult
x <= :: CommandResult -> CommandResult -> Bool
<= CommandResult
y = CommandResult -> Text
toResult CommandResult
x Text -> Text -> Bool
forall a. Ord a => a -> a -> Bool
<= CommandResult -> Text
toResult CommandResult
y

toResult :: CommandResult -> Text
toResult :: CommandResult -> Text
toResult CommandResult
r = CommandResult
r CommandResult -> Optic' A_Lens NoIx CommandResult Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx CommandResult Text
#result