-- 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.Photo where

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

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

instance FromJSON Photo where
  parseJSON :: Value -> Parser Photo
parseJSON = ([Text] -> Parser Photo)
-> (Value -> Parser Photo) -> Either [Text] Value -> Parser Photo
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Parser Photo
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Photo)
-> ([Text] -> String) -> [Text] -> Parser Photo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> String
forall a. Show a => a -> String
show) (Options -> Value -> Parser Photo
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
parseOptions) (Either [Text] Value -> Parser Photo)
-> (Value -> Either [Text] Value) -> Value -> Parser Photo
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 Photo where
  toJSON :: Photo -> Value
toJSON = Options -> Photo -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
serializeOptions