module HipChat.Types.WebPanel where
import Data.Aeson
import Data.Aeson.Casing
import Data.Aeson.Types
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as T
import GHC.Generics
import HipChat.Types.Icon
import HipChat.Types.Key
import HipChat.Types.Name
data WebPanelLocation = HipchatSidebarRight
deriving (Eq, Show)
instance ToJSON WebPanelLocation where
toJSON HipchatSidebarRight = "hipchat.sidebar.right"
instance FromJSON WebPanelLocation where
parseJSON (String "hipchat.sidebar.right") = return HipchatSidebarRight
parseJSON (String x) = fail $ "Unexpected string: \"" <> T.unpack x <> "\" when parsing WebPanelLocation"
parseJSON x = typeMismatch "WebPanelLocation" x
data WebPanel = WebPanel
{ webPanelIcon :: Maybe Icon
, webPanelKey :: Key
, webPanelLocation :: WebPanelLocation
, webPanelName :: Name
, webPanelUrl :: Text
, webPanelWeight :: Maybe Int
} deriving (Eq, Generic, Show)
webPanel :: Key -> Name -> Text -> WebPanel
webPanel k name url = WebPanel Nothing k HipchatSidebarRight name url Nothing
instance ToJSON WebPanel where
toJSON = genericToJSON (aesonDrop 8 camelCase){omitNothingFields = True}
instance FromJSON WebPanel where
parseJSON = genericParseJSON $ aesonDrop 8 camelCase