-- 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.Conversation.Typing
  ( TypingStatus (..),
  )
where

import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.OpenApi qualified as S
import Data.Schema
import Imports
import Wire.Arbitrary (Arbitrary, GenericUniform (..))

data TypingStatus
  = StartedTyping
  | StoppedTyping
  deriving stock (TypingStatus -> TypingStatus -> Bool
(TypingStatus -> TypingStatus -> Bool)
-> (TypingStatus -> TypingStatus -> Bool) -> Eq TypingStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TypingStatus -> TypingStatus -> Bool
== :: TypingStatus -> TypingStatus -> Bool
$c/= :: TypingStatus -> TypingStatus -> Bool
/= :: TypingStatus -> TypingStatus -> Bool
Eq, Eq TypingStatus
Eq TypingStatus =>
(TypingStatus -> TypingStatus -> Ordering)
-> (TypingStatus -> TypingStatus -> Bool)
-> (TypingStatus -> TypingStatus -> Bool)
-> (TypingStatus -> TypingStatus -> Bool)
-> (TypingStatus -> TypingStatus -> Bool)
-> (TypingStatus -> TypingStatus -> TypingStatus)
-> (TypingStatus -> TypingStatus -> TypingStatus)
-> Ord TypingStatus
TypingStatus -> TypingStatus -> Bool
TypingStatus -> TypingStatus -> Ordering
TypingStatus -> TypingStatus -> TypingStatus
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 :: TypingStatus -> TypingStatus -> Ordering
compare :: TypingStatus -> TypingStatus -> Ordering
$c< :: TypingStatus -> TypingStatus -> Bool
< :: TypingStatus -> TypingStatus -> Bool
$c<= :: TypingStatus -> TypingStatus -> Bool
<= :: TypingStatus -> TypingStatus -> Bool
$c> :: TypingStatus -> TypingStatus -> Bool
> :: TypingStatus -> TypingStatus -> Bool
$c>= :: TypingStatus -> TypingStatus -> Bool
>= :: TypingStatus -> TypingStatus -> Bool
$cmax :: TypingStatus -> TypingStatus -> TypingStatus
max :: TypingStatus -> TypingStatus -> TypingStatus
$cmin :: TypingStatus -> TypingStatus -> TypingStatus
min :: TypingStatus -> TypingStatus -> TypingStatus
Ord, Int -> TypingStatus -> ShowS
[TypingStatus] -> ShowS
TypingStatus -> String
(Int -> TypingStatus -> ShowS)
-> (TypingStatus -> String)
-> ([TypingStatus] -> ShowS)
-> Show TypingStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TypingStatus -> ShowS
showsPrec :: Int -> TypingStatus -> ShowS
$cshow :: TypingStatus -> String
show :: TypingStatus -> String
$cshowList :: [TypingStatus] -> ShowS
showList :: [TypingStatus] -> ShowS
Show, (forall x. TypingStatus -> Rep TypingStatus x)
-> (forall x. Rep TypingStatus x -> TypingStatus)
-> Generic TypingStatus
forall x. Rep TypingStatus x -> TypingStatus
forall x. TypingStatus -> Rep TypingStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TypingStatus -> Rep TypingStatus x
from :: forall x. TypingStatus -> Rep TypingStatus x
$cto :: forall x. Rep TypingStatus x -> TypingStatus
to :: forall x. Rep TypingStatus x -> TypingStatus
Generic)
  deriving (Gen TypingStatus
Gen TypingStatus
-> (TypingStatus -> [TypingStatus]) -> Arbitrary TypingStatus
TypingStatus -> [TypingStatus]
forall a. Gen a -> (a -> [a]) -> Arbitrary a
$carbitrary :: Gen TypingStatus
arbitrary :: Gen TypingStatus
$cshrink :: TypingStatus -> [TypingStatus]
shrink :: TypingStatus -> [TypingStatus]
Arbitrary) via (GenericUniform TypingStatus)
  deriving (Value -> Parser [TypingStatus]
Value -> Parser TypingStatus
(Value -> Parser TypingStatus)
-> (Value -> Parser [TypingStatus]) -> FromJSON TypingStatus
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser TypingStatus
parseJSON :: Value -> Parser TypingStatus
$cparseJSONList :: Value -> Parser [TypingStatus]
parseJSONList :: Value -> Parser [TypingStatus]
FromJSON, [TypingStatus] -> Value
[TypingStatus] -> Encoding
TypingStatus -> Value
TypingStatus -> Encoding
(TypingStatus -> Value)
-> (TypingStatus -> Encoding)
-> ([TypingStatus] -> Value)
-> ([TypingStatus] -> Encoding)
-> ToJSON TypingStatus
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: TypingStatus -> Value
toJSON :: TypingStatus -> Value
$ctoEncoding :: TypingStatus -> Encoding
toEncoding :: TypingStatus -> Encoding
$ctoJSONList :: [TypingStatus] -> Value
toJSONList :: [TypingStatus] -> Value
$ctoEncodingList :: [TypingStatus] -> Encoding
toEncodingList :: [TypingStatus] -> Encoding
ToJSON, Typeable TypingStatus
Typeable TypingStatus =>
(Proxy TypingStatus -> Declare (Definitions Schema) NamedSchema)
-> ToSchema TypingStatus
Proxy TypingStatus -> Declare (Definitions Schema) NamedSchema
forall a.
Typeable a =>
(Proxy a -> Declare (Definitions Schema) NamedSchema) -> ToSchema a
$cdeclareNamedSchema :: Proxy TypingStatus -> Declare (Definitions Schema) NamedSchema
declareNamedSchema :: Proxy TypingStatus -> Declare (Definitions Schema) NamedSchema
S.ToSchema) via Schema TypingStatus

instance ToSchema TypingStatus where
  schema :: ValueSchema NamedSwaggerDoc TypingStatus
schema =
    Text
-> SchemaP SwaggerDoc Object [Pair] TypingStatus TypingStatus
-> ValueSchema NamedSwaggerDoc TypingStatus
forall doc doc' a b.
HasObject doc doc' =>
Text
-> SchemaP doc Object [Pair] a b -> SchemaP doc' Value Value a b
object Text
"TypingData" (SchemaP SwaggerDoc Object [Pair] TypingStatus TypingStatus
 -> ValueSchema NamedSwaggerDoc TypingStatus)
-> SchemaP SwaggerDoc Object [Pair] TypingStatus TypingStatus
-> ValueSchema NamedSwaggerDoc TypingStatus
forall a b. (a -> b) -> a -> b
$
      Text
-> ValueSchema NamedSwaggerDoc TypingStatus
-> SchemaP SwaggerDoc Object [Pair] TypingStatus TypingStatus
forall doc' doc a b.
HasField doc' doc =>
Text
-> SchemaP doc' Value Value a b -> SchemaP doc Object [Pair] a b
field Text
"status" ValueSchema NamedSwaggerDoc TypingStatus
typingStatusSchema

typingStatusSchema :: ValueSchema NamedSwaggerDoc TypingStatus
typingStatusSchema :: ValueSchema NamedSwaggerDoc TypingStatus
typingStatusSchema =
  forall v doc a b.
(With v, HasEnum v doc) =>
Text
-> SchemaP [Value] v (Alt Maybe v) a b
-> SchemaP doc Value Value a b
enum @Text Text
"TypingStatus" (SchemaP [Value] Text (Alt Maybe Text) TypingStatus TypingStatus
 -> ValueSchema NamedSwaggerDoc TypingStatus)
-> SchemaP [Value] Text (Alt Maybe Text) TypingStatus TypingStatus
-> ValueSchema NamedSwaggerDoc TypingStatus
forall a b. (a -> b) -> a -> b
$
    Text
-> TypingStatus
-> SchemaP [Value] Text (Alt Maybe Text) TypingStatus TypingStatus
forall a b.
(ToJSON a, Eq a, Eq b) =>
a -> b -> SchemaP [Value] a (Alt Maybe a) b b
element Text
"started" TypingStatus
StartedTyping
      SchemaP [Value] Text (Alt Maybe Text) TypingStatus TypingStatus
-> SchemaP [Value] Text (Alt Maybe Text) TypingStatus TypingStatus
-> SchemaP [Value] Text (Alt Maybe Text) TypingStatus TypingStatus
forall a. Semigroup a => a -> a -> a
<> Text
-> TypingStatus
-> SchemaP [Value] Text (Alt Maybe Text) TypingStatus TypingStatus
forall a b.
(ToJSON a, Eq a, Eq b) =>
a -> b -> SchemaP [Value] a (Alt Maybe a) b b
element Text
"stopped" TypingStatus
StoppedTyping