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

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

data Phone = Phone
  { Phone -> Maybe Text
typ :: Maybe Text,
    Phone -> Maybe Text
value :: Maybe Text
  }
  deriving (Int -> Phone -> ShowS
[Phone] -> ShowS
Phone -> String
(Int -> Phone -> ShowS)
-> (Phone -> String) -> ([Phone] -> ShowS) -> Show Phone
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Phone -> ShowS
showsPrec :: Int -> Phone -> ShowS
$cshow :: Phone -> String
show :: Phone -> String
$cshowList :: [Phone] -> ShowS
showList :: [Phone] -> ShowS
Show, Phone -> Phone -> Bool
(Phone -> Phone -> Bool) -> (Phone -> Phone -> Bool) -> Eq Phone
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Phone -> Phone -> Bool
== :: Phone -> Phone -> Bool
$c/= :: Phone -> Phone -> Bool
/= :: Phone -> Phone -> Bool
Eq, Eq Phone
Eq Phone =>
(Phone -> Phone -> Ordering)
-> (Phone -> Phone -> Bool)
-> (Phone -> Phone -> Bool)
-> (Phone -> Phone -> Bool)
-> (Phone -> Phone -> Bool)
-> (Phone -> Phone -> Phone)
-> (Phone -> Phone -> Phone)
-> Ord Phone
Phone -> Phone -> Bool
Phone -> Phone -> Ordering
Phone -> Phone -> Phone
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Phone -> Phone -> Ordering
compare :: Phone -> Phone -> Ordering
$c< :: Phone -> Phone -> Bool
< :: Phone -> Phone -> Bool
$c<= :: Phone -> Phone -> Bool
<= :: Phone -> Phone -> Bool
$c> :: Phone -> Phone -> Bool
> :: Phone -> Phone -> Bool
$c>= :: Phone -> Phone -> Bool
>= :: Phone -> Phone -> Bool
$cmax :: Phone -> Phone -> Phone
max :: Phone -> Phone -> Phone
$cmin :: Phone -> Phone -> Phone
min :: Phone -> Phone -> Phone
Ord, (forall x. Phone -> Rep Phone x)
-> (forall x. Rep Phone x -> Phone) -> Generic Phone
forall x. Rep Phone x -> Phone
forall x. Phone -> Rep Phone x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Phone -> Rep Phone x
from :: forall x. Phone -> Rep Phone x
$cto :: forall x. Rep Phone x -> Phone
to :: forall x. Rep Phone x -> Phone
Generic)

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