{-# LANGUAGE StrictData #-}

-- 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.CustomBackend
  ( CustomBackend (..),
  )
where

import Control.Lens ((?~))
import Data.Misc (HttpsUrl)
import Data.OpenApi qualified as S
import Data.Schema
import Deriving.Aeson
import Imports
import Wire.Arbitrary (Arbitrary, GenericUniform (..))

data CustomBackend = CustomBackend
  { CustomBackend -> HttpsUrl
backendConfigJsonUrl :: HttpsUrl,
    CustomBackend -> HttpsUrl
backendWebappWelcomeUrl :: HttpsUrl
  }
  deriving stock (CustomBackend -> CustomBackend -> Bool
(CustomBackend -> CustomBackend -> Bool)
-> (CustomBackend -> CustomBackend -> Bool) -> Eq CustomBackend
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CustomBackend -> CustomBackend -> Bool
== :: CustomBackend -> CustomBackend -> Bool
$c/= :: CustomBackend -> CustomBackend -> Bool
/= :: CustomBackend -> CustomBackend -> Bool
Eq, Int -> CustomBackend -> ShowS
[CustomBackend] -> ShowS
CustomBackend -> String
(Int -> CustomBackend -> ShowS)
-> (CustomBackend -> String)
-> ([CustomBackend] -> ShowS)
-> Show CustomBackend
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CustomBackend -> ShowS
showsPrec :: Int -> CustomBackend -> ShowS
$cshow :: CustomBackend -> String
show :: CustomBackend -> String
$cshowList :: [CustomBackend] -> ShowS
showList :: [CustomBackend] -> ShowS
Show, (forall x. CustomBackend -> Rep CustomBackend x)
-> (forall x. Rep CustomBackend x -> CustomBackend)
-> Generic CustomBackend
forall x. Rep CustomBackend x -> CustomBackend
forall x. CustomBackend -> Rep CustomBackend x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CustomBackend -> Rep CustomBackend x
from :: forall x. CustomBackend -> Rep CustomBackend x
$cto :: forall x. Rep CustomBackend x -> CustomBackend
to :: forall x. Rep CustomBackend x -> CustomBackend
Generic)
  deriving (Gen CustomBackend
Gen CustomBackend
-> (CustomBackend -> [CustomBackend]) -> Arbitrary CustomBackend
CustomBackend -> [CustomBackend]
forall a. Gen a -> (a -> [a]) -> Arbitrary a
$carbitrary :: Gen CustomBackend
arbitrary :: Gen CustomBackend
$cshrink :: CustomBackend -> [CustomBackend]
shrink :: CustomBackend -> [CustomBackend]
Arbitrary) via (GenericUniform CustomBackend)
  deriving ([CustomBackend] -> Value
[CustomBackend] -> Encoding
CustomBackend -> Value
CustomBackend -> Encoding
(CustomBackend -> Value)
-> (CustomBackend -> Encoding)
-> ([CustomBackend] -> Value)
-> ([CustomBackend] -> Encoding)
-> ToJSON CustomBackend
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: CustomBackend -> Value
toJSON :: CustomBackend -> Value
$ctoEncoding :: CustomBackend -> Encoding
toEncoding :: CustomBackend -> Encoding
$ctoJSONList :: [CustomBackend] -> Value
toJSONList :: [CustomBackend] -> Value
$ctoEncodingList :: [CustomBackend] -> Encoding
toEncodingList :: [CustomBackend] -> Encoding
ToJSON, Value -> Parser [CustomBackend]
Value -> Parser CustomBackend
(Value -> Parser CustomBackend)
-> (Value -> Parser [CustomBackend]) -> FromJSON CustomBackend
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser CustomBackend
parseJSON :: Value -> Parser CustomBackend
$cparseJSONList :: Value -> Parser [CustomBackend]
parseJSONList :: Value -> Parser [CustomBackend]
FromJSON, Typeable CustomBackend
Typeable CustomBackend =>
(Proxy CustomBackend -> Declare (Definitions Schema) NamedSchema)
-> ToSchema CustomBackend
Proxy CustomBackend -> Declare (Definitions Schema) NamedSchema
forall a.
Typeable a =>
(Proxy a -> Declare (Definitions Schema) NamedSchema) -> ToSchema a
$cdeclareNamedSchema :: Proxy CustomBackend -> Declare (Definitions Schema) NamedSchema
declareNamedSchema :: Proxy CustomBackend -> Declare (Definitions Schema) NamedSchema
S.ToSchema) via (Schema CustomBackend)

instance ToSchema CustomBackend where
  schema :: ValueSchema NamedSwaggerDoc CustomBackend
schema =
    Text
-> (NamedSwaggerDoc -> NamedSwaggerDoc)
-> ObjectSchema SwaggerDoc CustomBackend
-> ValueSchema NamedSwaggerDoc CustomBackend
forall doc doc' a.
HasObject doc doc' =>
Text -> (doc' -> doc') -> ObjectSchema doc a -> ValueSchema doc' a
objectWithDocModifier Text
"CustomBackend" ((Maybe Text -> Identity (Maybe Text))
-> NamedSwaggerDoc -> Identity NamedSwaggerDoc
forall s a. HasDescription s a => Lens' s a
Lens' NamedSwaggerDoc (Maybe Text)
description ((Maybe Text -> Identity (Maybe Text))
 -> NamedSwaggerDoc -> Identity NamedSwaggerDoc)
-> Text -> NamedSwaggerDoc -> NamedSwaggerDoc
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text
"Description of a custom backend") (ObjectSchema SwaggerDoc CustomBackend
 -> ValueSchema NamedSwaggerDoc CustomBackend)
-> ObjectSchema SwaggerDoc CustomBackend
-> ValueSchema NamedSwaggerDoc CustomBackend
forall a b. (a -> b) -> a -> b
$
      HttpsUrl -> HttpsUrl -> CustomBackend
CustomBackend
        (HttpsUrl -> HttpsUrl -> CustomBackend)
-> SchemaP SwaggerDoc Object [Pair] CustomBackend HttpsUrl
-> SchemaP
     SwaggerDoc Object [Pair] CustomBackend (HttpsUrl -> CustomBackend)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CustomBackend -> HttpsUrl
backendConfigJsonUrl (CustomBackend -> HttpsUrl)
-> SchemaP SwaggerDoc Object [Pair] HttpsUrl HttpsUrl
-> SchemaP SwaggerDoc Object [Pair] CustomBackend HttpsUrl
forall (p :: * -> * -> *) a a' b.
Profunctor p =>
(a -> a') -> p a' b -> p a b
.= Text
-> (NamedSwaggerDoc -> NamedSwaggerDoc)
-> SchemaP NamedSwaggerDoc Value Value HttpsUrl HttpsUrl
-> SchemaP SwaggerDoc Object [Pair] HttpsUrl HttpsUrl
forall doc' doc a b.
HasField doc' doc =>
Text
-> (doc' -> doc')
-> SchemaP doc' Value Value a b
-> SchemaP doc Object [Pair] a b
fieldWithDocModifier Text
"config_json_url" ((Maybe Text -> Identity (Maybe Text))
-> NamedSwaggerDoc -> Identity NamedSwaggerDoc
forall s a. HasDescription s a => Lens' s a
Lens' NamedSwaggerDoc (Maybe Text)
description ((Maybe Text -> Identity (Maybe Text))
 -> NamedSwaggerDoc -> Identity NamedSwaggerDoc)
-> Text -> NamedSwaggerDoc -> NamedSwaggerDoc
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text
"the location of the custom backend's config.json file") SchemaP NamedSwaggerDoc Value Value HttpsUrl HttpsUrl
forall a. ToSchema a => ValueSchema NamedSwaggerDoc a
schema
        SchemaP
  SwaggerDoc Object [Pair] CustomBackend (HttpsUrl -> CustomBackend)
-> SchemaP SwaggerDoc Object [Pair] CustomBackend HttpsUrl
-> ObjectSchema SwaggerDoc CustomBackend
forall a b.
SchemaP SwaggerDoc Object [Pair] CustomBackend (a -> b)
-> SchemaP SwaggerDoc Object [Pair] CustomBackend a
-> SchemaP SwaggerDoc Object [Pair] CustomBackend b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CustomBackend -> HttpsUrl
backendWebappWelcomeUrl (CustomBackend -> HttpsUrl)
-> SchemaP SwaggerDoc Object [Pair] HttpsUrl HttpsUrl
-> SchemaP SwaggerDoc Object [Pair] CustomBackend HttpsUrl
forall (p :: * -> * -> *) a a' b.
Profunctor p =>
(a -> a') -> p a' b -> p a b
.= Text
-> (NamedSwaggerDoc -> NamedSwaggerDoc)
-> SchemaP NamedSwaggerDoc Value Value HttpsUrl HttpsUrl
-> SchemaP SwaggerDoc Object [Pair] HttpsUrl HttpsUrl
forall doc' doc a b.
HasField doc' doc =>
Text
-> (doc' -> doc')
-> SchemaP doc' Value Value a b
-> SchemaP doc Object [Pair] a b
fieldWithDocModifier Text
"webapp_welcome_url" ((Maybe Text -> Identity (Maybe Text))
-> NamedSwaggerDoc -> Identity NamedSwaggerDoc
forall s a. HasDescription s a => Lens' s a
Lens' NamedSwaggerDoc (Maybe Text)
description ((Maybe Text -> Identity (Maybe Text))
 -> NamedSwaggerDoc -> Identity NamedSwaggerDoc)
-> Text -> NamedSwaggerDoc -> NamedSwaggerDoc
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text
"the location of the custom webapp") SchemaP NamedSwaggerDoc Value Value HttpsUrl HttpsUrl
forall a. ToSchema a => ValueSchema NamedSwaggerDoc a
schema