-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Web.Scim.Schema.User.IM where

import Data.Aeson
import Data.Text (Text)
import GHC.Generics
import Web.Scim.Schema.Common

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

instance FromJSON IM where
  parseJSON :: Value -> Parser IM
parseJSON = ([Text] -> Parser IM)
-> (Value -> Parser IM) -> Either [Text] Value -> Parser IM
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Parser IM
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser IM) -> ([Text] -> String) -> [Text] -> Parser IM
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> String
forall a. Show a => a -> String
show) (Options -> Value -> Parser IM
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
parseOptions) (Either [Text] Value -> Parser IM)
-> (Value -> Either [Text] Value) -> Value -> Parser IM
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Either [Text] Value
forall (m :: * -> *). (m ~ Either [Text]) => Value -> m Value
jsonLower

instance ToJSON IM where
  toJSON :: IM -> Value
toJSON = Options -> IM -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
serializeOptions