{-# LANGUAGE TemplateHaskell #-}

-- 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 Wire.API.Bot
  ( AddBot,
    addBot,
    addBotService,
    addBotConv,
    addBotId,
    addBotClient,
    RemoveBot,
    removeBot,
    rmBotConv,
    rmBotId,
  )
where

import Control.Lens (makeLenses)
import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Id
import Data.OpenApi qualified as S
import Data.Schema
import Imports
import Wire.API.Provider.Service (ServiceRef)

-- AddBot ----------------------------------------------------------------------

data AddBot = AddBot
  { AddBot -> ServiceRef
_addBotService :: !ServiceRef,
    AddBot -> ConvId
_addBotConv :: !ConvId,
    AddBot -> BotId
_addBotId :: !BotId,
    AddBot -> ClientId
_addBotClient :: !ClientId
  }
  deriving (Value -> Parser [AddBot]
Value -> Parser AddBot
(Value -> Parser AddBot)
-> (Value -> Parser [AddBot]) -> FromJSON AddBot
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser AddBot
parseJSON :: Value -> Parser AddBot
$cparseJSONList :: Value -> Parser [AddBot]
parseJSONList :: Value -> Parser [AddBot]
FromJSON, [AddBot] -> Value
[AddBot] -> Encoding
AddBot -> Value
AddBot -> Encoding
(AddBot -> Value)
-> (AddBot -> Encoding)
-> ([AddBot] -> Value)
-> ([AddBot] -> Encoding)
-> ToJSON AddBot
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: AddBot -> Value
toJSON :: AddBot -> Value
$ctoEncoding :: AddBot -> Encoding
toEncoding :: AddBot -> Encoding
$ctoJSONList :: [AddBot] -> Value
toJSONList :: [AddBot] -> Value
$ctoEncodingList :: [AddBot] -> Encoding
toEncodingList :: [AddBot] -> Encoding
ToJSON, Typeable AddBot
Typeable AddBot =>
(Proxy AddBot -> Declare (Definitions Schema) NamedSchema)
-> ToSchema AddBot
Proxy AddBot -> Declare (Definitions Schema) NamedSchema
forall a.
Typeable a =>
(Proxy a -> Declare (Definitions Schema) NamedSchema) -> ToSchema a
$cdeclareNamedSchema :: Proxy AddBot -> Declare (Definitions Schema) NamedSchema
declareNamedSchema :: Proxy AddBot -> Declare (Definitions Schema) NamedSchema
S.ToSchema) via Schema AddBot

addBot :: ServiceRef -> ConvId -> BotId -> ClientId -> AddBot
addBot :: ServiceRef -> ConvId -> BotId -> ClientId -> AddBot
addBot = ServiceRef -> ConvId -> BotId -> ClientId -> AddBot
AddBot

instance ToSchema AddBot where
  schema :: ValueSchema NamedSwaggerDoc AddBot
schema =
    Text
-> SchemaP SwaggerDoc Object [Pair] AddBot AddBot
-> ValueSchema NamedSwaggerDoc AddBot
forall doc doc' a b.
HasObject doc doc' =>
Text
-> SchemaP doc Object [Pair] a b -> SchemaP doc' Value Value a b
object Text
"AddBot" (SchemaP SwaggerDoc Object [Pair] AddBot AddBot
 -> ValueSchema NamedSwaggerDoc AddBot)
-> SchemaP SwaggerDoc Object [Pair] AddBot AddBot
-> ValueSchema NamedSwaggerDoc AddBot
forall a b. (a -> b) -> a -> b
$
      ServiceRef -> ConvId -> BotId -> ClientId -> AddBot
AddBot
        (ServiceRef -> ConvId -> BotId -> ClientId -> AddBot)
-> SchemaP SwaggerDoc Object [Pair] AddBot ServiceRef
-> SchemaP
     SwaggerDoc
     Object
     [Pair]
     AddBot
     (ConvId -> BotId -> ClientId -> AddBot)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AddBot -> ServiceRef
_addBotService (AddBot -> ServiceRef)
-> SchemaP SwaggerDoc Object [Pair] ServiceRef ServiceRef
-> SchemaP SwaggerDoc Object [Pair] AddBot ServiceRef
forall (p :: * -> * -> *) a a' b.
Profunctor p =>
(a -> a') -> p a' b -> p a b
.= Text
-> SchemaP NamedSwaggerDoc Value Value ServiceRef ServiceRef
-> SchemaP SwaggerDoc Object [Pair] ServiceRef ServiceRef
forall doc' doc a b.
HasField doc' doc =>
Text
-> SchemaP doc' Value Value a b -> SchemaP doc Object [Pair] a b
field Text
"service" SchemaP NamedSwaggerDoc Value Value ServiceRef ServiceRef
forall a. ToSchema a => ValueSchema NamedSwaggerDoc a
schema
        SchemaP
  SwaggerDoc
  Object
  [Pair]
  AddBot
  (ConvId -> BotId -> ClientId -> AddBot)
-> SchemaP SwaggerDoc Object [Pair] AddBot ConvId
-> SchemaP
     SwaggerDoc Object [Pair] AddBot (BotId -> ClientId -> AddBot)
forall a b.
SchemaP SwaggerDoc Object [Pair] AddBot (a -> b)
-> SchemaP SwaggerDoc Object [Pair] AddBot a
-> SchemaP SwaggerDoc Object [Pair] AddBot b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AddBot -> ConvId
_addBotConv (AddBot -> ConvId)
-> SchemaP SwaggerDoc Object [Pair] ConvId ConvId
-> SchemaP SwaggerDoc Object [Pair] AddBot ConvId
forall (p :: * -> * -> *) a a' b.
Profunctor p =>
(a -> a') -> p a' b -> p a b
.= Text
-> SchemaP NamedSwaggerDoc Value Value ConvId ConvId
-> SchemaP SwaggerDoc Object [Pair] ConvId ConvId
forall doc' doc a b.
HasField doc' doc =>
Text
-> SchemaP doc' Value Value a b -> SchemaP doc Object [Pair] a b
field Text
"conversation" SchemaP NamedSwaggerDoc Value Value ConvId ConvId
forall a. ToSchema a => ValueSchema NamedSwaggerDoc a
schema
        SchemaP
  SwaggerDoc Object [Pair] AddBot (BotId -> ClientId -> AddBot)
-> SchemaP SwaggerDoc Object [Pair] AddBot BotId
-> SchemaP SwaggerDoc Object [Pair] AddBot (ClientId -> AddBot)
forall a b.
SchemaP SwaggerDoc Object [Pair] AddBot (a -> b)
-> SchemaP SwaggerDoc Object [Pair] AddBot a
-> SchemaP SwaggerDoc Object [Pair] AddBot b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AddBot -> BotId
_addBotId (AddBot -> BotId)
-> SchemaP SwaggerDoc Object [Pair] BotId BotId
-> SchemaP SwaggerDoc Object [Pair] AddBot BotId
forall (p :: * -> * -> *) a a' b.
Profunctor p =>
(a -> a') -> p a' b -> p a b
.= Text
-> SchemaP NamedSwaggerDoc Value Value BotId BotId
-> SchemaP SwaggerDoc Object [Pair] BotId BotId
forall doc' doc a b.
HasField doc' doc =>
Text
-> SchemaP doc' Value Value a b -> SchemaP doc Object [Pair] a b
field Text
"bot" SchemaP NamedSwaggerDoc Value Value BotId BotId
forall a. ToSchema a => ValueSchema NamedSwaggerDoc a
schema
        SchemaP SwaggerDoc Object [Pair] AddBot (ClientId -> AddBot)
-> SchemaP SwaggerDoc Object [Pair] AddBot ClientId
-> SchemaP SwaggerDoc Object [Pair] AddBot AddBot
forall a b.
SchemaP SwaggerDoc Object [Pair] AddBot (a -> b)
-> SchemaP SwaggerDoc Object [Pair] AddBot a
-> SchemaP SwaggerDoc Object [Pair] AddBot b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AddBot -> ClientId
_addBotClient (AddBot -> ClientId)
-> SchemaP SwaggerDoc Object [Pair] ClientId ClientId
-> SchemaP SwaggerDoc Object [Pair] AddBot ClientId
forall (p :: * -> * -> *) a a' b.
Profunctor p =>
(a -> a') -> p a' b -> p a b
.= Text
-> SchemaP NamedSwaggerDoc Value Value ClientId ClientId
-> SchemaP SwaggerDoc Object [Pair] ClientId ClientId
forall doc' doc a b.
HasField doc' doc =>
Text
-> SchemaP doc' Value Value a b -> SchemaP doc Object [Pair] a b
field Text
"client" SchemaP NamedSwaggerDoc Value Value ClientId ClientId
forall a. ToSchema a => ValueSchema NamedSwaggerDoc a
schema

-- RemoveBot ------------------------------------------------------------------

data RemoveBot = RemoveBot
  { RemoveBot -> ConvId
_rmBotConv :: !ConvId,
    RemoveBot -> BotId
_rmBotId :: !BotId
  }
  deriving (Value -> Parser [RemoveBot]
Value -> Parser RemoveBot
(Value -> Parser RemoveBot)
-> (Value -> Parser [RemoveBot]) -> FromJSON RemoveBot
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser RemoveBot
parseJSON :: Value -> Parser RemoveBot
$cparseJSONList :: Value -> Parser [RemoveBot]
parseJSONList :: Value -> Parser [RemoveBot]
FromJSON, [RemoveBot] -> Value
[RemoveBot] -> Encoding
RemoveBot -> Value
RemoveBot -> Encoding
(RemoveBot -> Value)
-> (RemoveBot -> Encoding)
-> ([RemoveBot] -> Value)
-> ([RemoveBot] -> Encoding)
-> ToJSON RemoveBot
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: RemoveBot -> Value
toJSON :: RemoveBot -> Value
$ctoEncoding :: RemoveBot -> Encoding
toEncoding :: RemoveBot -> Encoding
$ctoJSONList :: [RemoveBot] -> Value
toJSONList :: [RemoveBot] -> Value
$ctoEncodingList :: [RemoveBot] -> Encoding
toEncodingList :: [RemoveBot] -> Encoding
ToJSON, Typeable RemoveBot
Typeable RemoveBot =>
(Proxy RemoveBot -> Declare (Definitions Schema) NamedSchema)
-> ToSchema RemoveBot
Proxy RemoveBot -> Declare (Definitions Schema) NamedSchema
forall a.
Typeable a =>
(Proxy a -> Declare (Definitions Schema) NamedSchema) -> ToSchema a
$cdeclareNamedSchema :: Proxy RemoveBot -> Declare (Definitions Schema) NamedSchema
declareNamedSchema :: Proxy RemoveBot -> Declare (Definitions Schema) NamedSchema
S.ToSchema) via Schema RemoveBot

removeBot :: ConvId -> BotId -> RemoveBot
removeBot :: ConvId -> BotId -> RemoveBot
removeBot = ConvId -> BotId -> RemoveBot
RemoveBot

instance ToSchema RemoveBot where
  schema :: ValueSchema NamedSwaggerDoc RemoveBot
schema =
    Text
-> SchemaP SwaggerDoc Object [Pair] RemoveBot RemoveBot
-> ValueSchema NamedSwaggerDoc RemoveBot
forall doc doc' a b.
HasObject doc doc' =>
Text
-> SchemaP doc Object [Pair] a b -> SchemaP doc' Value Value a b
object Text
"RemoveBot" (SchemaP SwaggerDoc Object [Pair] RemoveBot RemoveBot
 -> ValueSchema NamedSwaggerDoc RemoveBot)
-> SchemaP SwaggerDoc Object [Pair] RemoveBot RemoveBot
-> ValueSchema NamedSwaggerDoc RemoveBot
forall a b. (a -> b) -> a -> b
$
      ConvId -> BotId -> RemoveBot
RemoveBot
        (ConvId -> BotId -> RemoveBot)
-> SchemaP SwaggerDoc Object [Pair] RemoveBot ConvId
-> SchemaP SwaggerDoc Object [Pair] RemoveBot (BotId -> RemoveBot)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RemoveBot -> ConvId
_rmBotConv (RemoveBot -> ConvId)
-> SchemaP SwaggerDoc Object [Pair] ConvId ConvId
-> SchemaP SwaggerDoc Object [Pair] RemoveBot ConvId
forall (p :: * -> * -> *) a a' b.
Profunctor p =>
(a -> a') -> p a' b -> p a b
.= Text
-> SchemaP NamedSwaggerDoc Value Value ConvId ConvId
-> SchemaP SwaggerDoc Object [Pair] ConvId ConvId
forall doc' doc a b.
HasField doc' doc =>
Text
-> SchemaP doc' Value Value a b -> SchemaP doc Object [Pair] a b
field Text
"conversation" SchemaP NamedSwaggerDoc Value Value ConvId ConvId
forall a. ToSchema a => ValueSchema NamedSwaggerDoc a
schema
        SchemaP SwaggerDoc Object [Pair] RemoveBot (BotId -> RemoveBot)
-> SchemaP SwaggerDoc Object [Pair] RemoveBot BotId
-> SchemaP SwaggerDoc Object [Pair] RemoveBot RemoveBot
forall a b.
SchemaP SwaggerDoc Object [Pair] RemoveBot (a -> b)
-> SchemaP SwaggerDoc Object [Pair] RemoveBot a
-> SchemaP SwaggerDoc Object [Pair] RemoveBot b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> RemoveBot -> BotId
_rmBotId (RemoveBot -> BotId)
-> SchemaP SwaggerDoc Object [Pair] BotId BotId
-> SchemaP SwaggerDoc Object [Pair] RemoveBot BotId
forall (p :: * -> * -> *) a a' b.
Profunctor p =>
(a -> a') -> p a' b -> p a b
.= Text
-> SchemaP NamedSwaggerDoc Value Value BotId BotId
-> SchemaP SwaggerDoc Object [Pair] BotId BotId
forall doc' doc a b.
HasField doc' doc =>
Text
-> SchemaP doc' Value Value a b -> SchemaP doc Object [Pair] a b
field Text
"bot" SchemaP NamedSwaggerDoc Value Value BotId BotId
forall a. ToSchema a => ValueSchema NamedSwaggerDoc a
schema

makeLenses ''AddBot
makeLenses ''RemoveBot