-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2020 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.Address where

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

data Address = Address
  { Address -> Maybe Text
formatted :: Maybe Text,
    Address -> Maybe Text
streetAddress :: Maybe Text,
    Address -> Maybe Text
locality :: Maybe Text,
    Address -> Maybe Text
region :: Maybe Text,
    Address -> Maybe Text
postalCode :: Maybe Text,
    -- TODO: country is specified as ISO3166, but example uses "USA"
    Address -> Maybe Text
country :: Maybe Text,
    Address -> Maybe Text
typ :: Maybe Text,
    Address -> Maybe ScimBool
primary :: Maybe ScimBool
  }
  deriving (Int -> Address -> ShowS
[Address] -> ShowS
Address -> String
(Int -> Address -> ShowS)
-> (Address -> String) -> ([Address] -> ShowS) -> Show Address
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Address] -> ShowS
$cshowList :: [Address] -> ShowS
show :: Address -> String
$cshow :: Address -> String
showsPrec :: Int -> Address -> ShowS
$cshowsPrec :: Int -> Address -> ShowS
Show, Address -> Address -> Bool
(Address -> Address -> Bool)
-> (Address -> Address -> Bool) -> Eq Address
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Address -> Address -> Bool
$c/= :: Address -> Address -> Bool
== :: Address -> Address -> Bool
$c== :: Address -> Address -> Bool
Eq, (forall x. Address -> Rep Address x)
-> (forall x. Rep Address x -> Address) -> Generic Address
forall x. Rep Address x -> Address
forall x. Address -> Rep Address x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Address x -> Address
$cfrom :: forall x. Address -> Rep Address x
Generic)

instance FromJSON Address where
  parseJSON :: Value -> Parser Address
parseJSON = Options -> Value -> Parser Address
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
parseOptions (Value -> Parser Address)
-> (Value -> Value) -> Value -> Parser Address
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Value
jsonLower

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