-- 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.Team.Size
  ( TeamSize (TeamSize),
  )
where

import Control.Lens ((?~))
import Data.Aeson qualified as A
import Data.OpenApi qualified as S
import Data.Schema
import Imports
import Numeric.Natural

newtype TeamSize = TeamSize Natural
  deriving (Int -> TeamSize -> ShowS
[TeamSize] -> ShowS
TeamSize -> String
(Int -> TeamSize -> ShowS)
-> (TeamSize -> String) -> ([TeamSize] -> ShowS) -> Show TeamSize
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TeamSize -> ShowS
showsPrec :: Int -> TeamSize -> ShowS
$cshow :: TeamSize -> String
show :: TeamSize -> String
$cshowList :: [TeamSize] -> ShowS
showList :: [TeamSize] -> ShowS
Show, TeamSize -> TeamSize -> Bool
(TeamSize -> TeamSize -> Bool)
-> (TeamSize -> TeamSize -> Bool) -> Eq TeamSize
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TeamSize -> TeamSize -> Bool
== :: TeamSize -> TeamSize -> Bool
$c/= :: TeamSize -> TeamSize -> Bool
/= :: TeamSize -> TeamSize -> Bool
Eq)
  deriving ([TeamSize] -> Value
[TeamSize] -> Encoding
TeamSize -> Value
TeamSize -> Encoding
(TeamSize -> Value)
-> (TeamSize -> Encoding)
-> ([TeamSize] -> Value)
-> ([TeamSize] -> Encoding)
-> ToJSON TeamSize
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: TeamSize -> Value
toJSON :: TeamSize -> Value
$ctoEncoding :: TeamSize -> Encoding
toEncoding :: TeamSize -> Encoding
$ctoJSONList :: [TeamSize] -> Value
toJSONList :: [TeamSize] -> Value
$ctoEncodingList :: [TeamSize] -> Encoding
toEncodingList :: [TeamSize] -> Encoding
A.ToJSON, Value -> Parser [TeamSize]
Value -> Parser TeamSize
(Value -> Parser TeamSize)
-> (Value -> Parser [TeamSize]) -> FromJSON TeamSize
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser TeamSize
parseJSON :: Value -> Parser TeamSize
$cparseJSONList :: Value -> Parser [TeamSize]
parseJSONList :: Value -> Parser [TeamSize]
A.FromJSON, Typeable TeamSize
Typeable TeamSize =>
(Proxy TeamSize -> Declare (Definitions Schema) NamedSchema)
-> ToSchema TeamSize
Proxy TeamSize -> Declare (Definitions Schema) NamedSchema
forall a.
Typeable a =>
(Proxy a -> Declare (Definitions Schema) NamedSchema) -> ToSchema a
$cdeclareNamedSchema :: Proxy TeamSize -> Declare (Definitions Schema) NamedSchema
declareNamedSchema :: Proxy TeamSize -> Declare (Definitions Schema) NamedSchema
S.ToSchema) via (Schema TeamSize)

instance ToSchema TeamSize where
  schema :: ValueSchema NamedSwaggerDoc TeamSize
schema =
    Text
-> (NamedSwaggerDoc -> NamedSwaggerDoc)
-> ObjectSchema SwaggerDoc TeamSize
-> ValueSchema NamedSwaggerDoc TeamSize
forall doc doc' a.
HasObject doc doc' =>
Text -> (doc' -> doc') -> ObjectSchema doc a -> ValueSchema doc' a
objectWithDocModifier Text
"TeamSize" ((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
"A simple object with a total number of team members.") (ObjectSchema SwaggerDoc TeamSize
 -> ValueSchema NamedSwaggerDoc TeamSize)
-> ObjectSchema SwaggerDoc TeamSize
-> ValueSchema NamedSwaggerDoc TeamSize
forall a b. (a -> b) -> a -> b
$
      Natural -> TeamSize
TeamSize (Natural -> TeamSize)
-> SchemaP SwaggerDoc Object [Pair] TeamSize Natural
-> ObjectSchema SwaggerDoc TeamSize
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (TeamSize -> Natural
unTeamSize (TeamSize -> Natural)
-> SchemaP SwaggerDoc Object [Pair] Natural Natural
-> SchemaP SwaggerDoc Object [Pair] TeamSize Natural
forall (p :: * -> * -> *) a a' b.
Profunctor p =>
(a -> a') -> p a' b -> p a b
.= Text
-> (NamedSwaggerDoc -> NamedSwaggerDoc)
-> SchemaP NamedSwaggerDoc Value Value Natural Natural
-> SchemaP SwaggerDoc Object [Pair] Natural Natural
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
"teamSize" ((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
"Team size.") SchemaP NamedSwaggerDoc Value Value Natural Natural
forall a. ToSchema a => ValueSchema NamedSwaggerDoc a
schema)
    where
      unTeamSize :: TeamSize -> Natural
      unTeamSize :: TeamSize -> Natural
unTeamSize (TeamSize Natural
n) = Natural
n