-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2023 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 Wire.API.Federation.API.Brig.Notifications where

import Data.Aeson
import Data.Id
import Data.OpenApi (ToSchema)
import Data.Range
import Imports
import Wire.API.Federation.Component
import Wire.API.Federation.Endpoint
import Wire.API.Federation.HasNotificationEndpoint
import Wire.API.Util.Aeson
import Wire.Arbitrary

type UserDeletedNotificationMaxConnections = 1000

data UserDeletedConnectionsNotification = UserDeletedConnectionsNotification
  { -- | This is qualified implicitly by the origin domain
    UserDeletedConnectionsNotification -> UserId
user :: UserId,
    -- | These are qualified implicitly by the target domain
    UserDeletedConnectionsNotification
-> Range 1 UserDeletedNotificationMaxConnections [UserId]
connections :: Range 1 UserDeletedNotificationMaxConnections [UserId]
  }
  deriving stock (UserDeletedConnectionsNotification
-> UserDeletedConnectionsNotification -> Bool
(UserDeletedConnectionsNotification
 -> UserDeletedConnectionsNotification -> Bool)
-> (UserDeletedConnectionsNotification
    -> UserDeletedConnectionsNotification -> Bool)
-> Eq UserDeletedConnectionsNotification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UserDeletedConnectionsNotification
-> UserDeletedConnectionsNotification -> Bool
== :: UserDeletedConnectionsNotification
-> UserDeletedConnectionsNotification -> Bool
$c/= :: UserDeletedConnectionsNotification
-> UserDeletedConnectionsNotification -> Bool
/= :: UserDeletedConnectionsNotification
-> UserDeletedConnectionsNotification -> Bool
Eq, Int -> UserDeletedConnectionsNotification -> ShowS
[UserDeletedConnectionsNotification] -> ShowS
UserDeletedConnectionsNotification -> String
(Int -> UserDeletedConnectionsNotification -> ShowS)
-> (UserDeletedConnectionsNotification -> String)
-> ([UserDeletedConnectionsNotification] -> ShowS)
-> Show UserDeletedConnectionsNotification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UserDeletedConnectionsNotification -> ShowS
showsPrec :: Int -> UserDeletedConnectionsNotification -> ShowS
$cshow :: UserDeletedConnectionsNotification -> String
show :: UserDeletedConnectionsNotification -> String
$cshowList :: [UserDeletedConnectionsNotification] -> ShowS
showList :: [UserDeletedConnectionsNotification] -> ShowS
Show, (forall x.
 UserDeletedConnectionsNotification
 -> Rep UserDeletedConnectionsNotification x)
-> (forall x.
    Rep UserDeletedConnectionsNotification x
    -> UserDeletedConnectionsNotification)
-> Generic UserDeletedConnectionsNotification
forall x.
Rep UserDeletedConnectionsNotification x
-> UserDeletedConnectionsNotification
forall x.
UserDeletedConnectionsNotification
-> Rep UserDeletedConnectionsNotification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
UserDeletedConnectionsNotification
-> Rep UserDeletedConnectionsNotification x
from :: forall x.
UserDeletedConnectionsNotification
-> Rep UserDeletedConnectionsNotification x
$cto :: forall x.
Rep UserDeletedConnectionsNotification x
-> UserDeletedConnectionsNotification
to :: forall x.
Rep UserDeletedConnectionsNotification x
-> UserDeletedConnectionsNotification
Generic)
  deriving (Gen UserDeletedConnectionsNotification
Gen UserDeletedConnectionsNotification
-> (UserDeletedConnectionsNotification
    -> [UserDeletedConnectionsNotification])
-> Arbitrary UserDeletedConnectionsNotification
UserDeletedConnectionsNotification
-> [UserDeletedConnectionsNotification]
forall a. Gen a -> (a -> [a]) -> Arbitrary a
$carbitrary :: Gen UserDeletedConnectionsNotification
arbitrary :: Gen UserDeletedConnectionsNotification
$cshrink :: UserDeletedConnectionsNotification
-> [UserDeletedConnectionsNotification]
shrink :: UserDeletedConnectionsNotification
-> [UserDeletedConnectionsNotification]
Arbitrary) via (GenericUniform UserDeletedConnectionsNotification)
  deriving (Value -> Parser [UserDeletedConnectionsNotification]
Value -> Parser UserDeletedConnectionsNotification
(Value -> Parser UserDeletedConnectionsNotification)
-> (Value -> Parser [UserDeletedConnectionsNotification])
-> FromJSON UserDeletedConnectionsNotification
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser UserDeletedConnectionsNotification
parseJSON :: Value -> Parser UserDeletedConnectionsNotification
$cparseJSONList :: Value -> Parser [UserDeletedConnectionsNotification]
parseJSONList :: Value -> Parser [UserDeletedConnectionsNotification]
FromJSON, [UserDeletedConnectionsNotification] -> Value
[UserDeletedConnectionsNotification] -> Encoding
UserDeletedConnectionsNotification -> Value
UserDeletedConnectionsNotification -> Encoding
(UserDeletedConnectionsNotification -> Value)
-> (UserDeletedConnectionsNotification -> Encoding)
-> ([UserDeletedConnectionsNotification] -> Value)
-> ([UserDeletedConnectionsNotification] -> Encoding)
-> ToJSON UserDeletedConnectionsNotification
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: UserDeletedConnectionsNotification -> Value
toJSON :: UserDeletedConnectionsNotification -> Value
$ctoEncoding :: UserDeletedConnectionsNotification -> Encoding
toEncoding :: UserDeletedConnectionsNotification -> Encoding
$ctoJSONList :: [UserDeletedConnectionsNotification] -> Value
toJSONList :: [UserDeletedConnectionsNotification] -> Value
$ctoEncodingList :: [UserDeletedConnectionsNotification] -> Encoding
toEncodingList :: [UserDeletedConnectionsNotification] -> Encoding
ToJSON) via (CustomEncoded UserDeletedConnectionsNotification)

data BrigNotificationTag = OnUserDeletedConnectionsTag
  deriving (Int -> BrigNotificationTag -> ShowS
[BrigNotificationTag] -> ShowS
BrigNotificationTag -> String
(Int -> BrigNotificationTag -> ShowS)
-> (BrigNotificationTag -> String)
-> ([BrigNotificationTag] -> ShowS)
-> Show BrigNotificationTag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BrigNotificationTag -> ShowS
showsPrec :: Int -> BrigNotificationTag -> ShowS
$cshow :: BrigNotificationTag -> String
show :: BrigNotificationTag -> String
$cshowList :: [BrigNotificationTag] -> ShowS
showList :: [BrigNotificationTag] -> ShowS
Show, BrigNotificationTag -> BrigNotificationTag -> Bool
(BrigNotificationTag -> BrigNotificationTag -> Bool)
-> (BrigNotificationTag -> BrigNotificationTag -> Bool)
-> Eq BrigNotificationTag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BrigNotificationTag -> BrigNotificationTag -> Bool
== :: BrigNotificationTag -> BrigNotificationTag -> Bool
$c/= :: BrigNotificationTag -> BrigNotificationTag -> Bool
/= :: BrigNotificationTag -> BrigNotificationTag -> Bool
Eq, (forall x. BrigNotificationTag -> Rep BrigNotificationTag x)
-> (forall x. Rep BrigNotificationTag x -> BrigNotificationTag)
-> Generic BrigNotificationTag
forall x. Rep BrigNotificationTag x -> BrigNotificationTag
forall x. BrigNotificationTag -> Rep BrigNotificationTag x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BrigNotificationTag -> Rep BrigNotificationTag x
from :: forall x. BrigNotificationTag -> Rep BrigNotificationTag x
$cto :: forall x. Rep BrigNotificationTag x -> BrigNotificationTag
to :: forall x. Rep BrigNotificationTag x -> BrigNotificationTag
Generic, BrigNotificationTag
BrigNotificationTag
-> BrigNotificationTag -> Bounded BrigNotificationTag
forall a. a -> a -> Bounded a
$cminBound :: BrigNotificationTag
minBound :: BrigNotificationTag
$cmaxBound :: BrigNotificationTag
maxBound :: BrigNotificationTag
Bounded, Int -> BrigNotificationTag
BrigNotificationTag -> Int
BrigNotificationTag -> [BrigNotificationTag]
BrigNotificationTag -> BrigNotificationTag
BrigNotificationTag -> BrigNotificationTag -> [BrigNotificationTag]
BrigNotificationTag
-> BrigNotificationTag
-> BrigNotificationTag
-> [BrigNotificationTag]
(BrigNotificationTag -> BrigNotificationTag)
-> (BrigNotificationTag -> BrigNotificationTag)
-> (Int -> BrigNotificationTag)
-> (BrigNotificationTag -> Int)
-> (BrigNotificationTag -> [BrigNotificationTag])
-> (BrigNotificationTag
    -> BrigNotificationTag -> [BrigNotificationTag])
-> (BrigNotificationTag
    -> BrigNotificationTag -> [BrigNotificationTag])
-> (BrigNotificationTag
    -> BrigNotificationTag
    -> BrigNotificationTag
    -> [BrigNotificationTag])
-> Enum BrigNotificationTag
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: BrigNotificationTag -> BrigNotificationTag
succ :: BrigNotificationTag -> BrigNotificationTag
$cpred :: BrigNotificationTag -> BrigNotificationTag
pred :: BrigNotificationTag -> BrigNotificationTag
$ctoEnum :: Int -> BrigNotificationTag
toEnum :: Int -> BrigNotificationTag
$cfromEnum :: BrigNotificationTag -> Int
fromEnum :: BrigNotificationTag -> Int
$cenumFrom :: BrigNotificationTag -> [BrigNotificationTag]
enumFrom :: BrigNotificationTag -> [BrigNotificationTag]
$cenumFromThen :: BrigNotificationTag -> BrigNotificationTag -> [BrigNotificationTag]
enumFromThen :: BrigNotificationTag -> BrigNotificationTag -> [BrigNotificationTag]
$cenumFromTo :: BrigNotificationTag -> BrigNotificationTag -> [BrigNotificationTag]
enumFromTo :: BrigNotificationTag -> BrigNotificationTag -> [BrigNotificationTag]
$cenumFromThenTo :: BrigNotificationTag
-> BrigNotificationTag
-> BrigNotificationTag
-> [BrigNotificationTag]
enumFromThenTo :: BrigNotificationTag
-> BrigNotificationTag
-> BrigNotificationTag
-> [BrigNotificationTag]
Enum)

instance IsNotificationTag BrigNotificationTag where
  type NotificationComponent _ = 'Brig

instance HasNotificationEndpoint 'OnUserDeletedConnectionsTag where
  type Payload 'OnUserDeletedConnectionsTag = UserDeletedConnectionsNotification
  type NotificationPath 'OnUserDeletedConnectionsTag = "on-user-deleted-connections"

instance ToSchema UserDeletedConnectionsNotification

-- | All the notification endpoints return an 'EmptyResponse'.
type BrigNotificationAPI =
  NotificationFedEndpoint 'OnUserDeletedConnectionsTag