module TD.Data.CommunityMemberStatus
  (CommunityMemberStatus(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.CommunityAdministratorRights as CommunityAdministratorRights

-- | Provides information about the status of a member in a community
data CommunityMemberStatus
  = CommunityMemberStatusCreator -- ^ The user is the owner of the community and has all the administrator privileges
  | CommunityMemberStatusAdministrator -- ^ The user is a member of the community and has some additional privileges
    { CommunityMemberStatus -> Maybe Bool
can_be_edited :: Maybe Bool                                                      -- ^ True, if the current user can edit the administrator privileges for the called user
    , CommunityMemberStatus -> Maybe CommunityAdministratorRights
rights        :: Maybe CommunityAdministratorRights.CommunityAdministratorRights -- ^ Rights of the administrator
    }
  | CommunityMemberStatusMember -- ^ The user is a member of the community, without any additional privileges or restrictions
  | CommunityMemberStatusLeft -- ^ The user or the chat is not a community member
  | CommunityMemberStatusBanned -- ^ The user or the chat was banned in the community; implies ban in all chats in the community
  deriving (CommunityMemberStatus -> CommunityMemberStatus -> Bool
(CommunityMemberStatus -> CommunityMemberStatus -> Bool)
-> (CommunityMemberStatus -> CommunityMemberStatus -> Bool)
-> Eq CommunityMemberStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CommunityMemberStatus -> CommunityMemberStatus -> Bool
== :: CommunityMemberStatus -> CommunityMemberStatus -> Bool
$c/= :: CommunityMemberStatus -> CommunityMemberStatus -> Bool
/= :: CommunityMemberStatus -> CommunityMemberStatus -> Bool
Eq, Int -> CommunityMemberStatus -> ShowS
[CommunityMemberStatus] -> ShowS
CommunityMemberStatus -> String
(Int -> CommunityMemberStatus -> ShowS)
-> (CommunityMemberStatus -> String)
-> ([CommunityMemberStatus] -> ShowS)
-> Show CommunityMemberStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CommunityMemberStatus -> ShowS
showsPrec :: Int -> CommunityMemberStatus -> ShowS
$cshow :: CommunityMemberStatus -> String
show :: CommunityMemberStatus -> String
$cshowList :: [CommunityMemberStatus] -> ShowS
showList :: [CommunityMemberStatus] -> ShowS
Show)

instance I.ShortShow CommunityMemberStatus where
  shortShow :: CommunityMemberStatus -> String
shortShow CommunityMemberStatus
CommunityMemberStatusCreator
      = String
"CommunityMemberStatusCreator"
  shortShow CommunityMemberStatusAdministrator
    { can_be_edited :: CommunityMemberStatus -> Maybe Bool
can_be_edited = Maybe Bool
can_be_edited_
    , rights :: CommunityMemberStatus -> Maybe CommunityAdministratorRights
rights        = Maybe CommunityAdministratorRights
rights_
    }
      = String
"CommunityMemberStatusAdministrator"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"can_be_edited" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_be_edited_
        , String
"rights"        String -> Maybe CommunityAdministratorRights -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe CommunityAdministratorRights
rights_
        ]
  shortShow CommunityMemberStatus
CommunityMemberStatusMember
      = String
"CommunityMemberStatusMember"
  shortShow CommunityMemberStatus
CommunityMemberStatusLeft
      = String
"CommunityMemberStatusLeft"
  shortShow CommunityMemberStatus
CommunityMemberStatusBanned
      = String
"CommunityMemberStatusBanned"

instance AT.FromJSON CommunityMemberStatus where
  parseJSON :: Value -> Parser CommunityMemberStatus
parseJSON v :: Value
v@(AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"communityMemberStatusCreator"       -> CommunityMemberStatus -> Parser CommunityMemberStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CommunityMemberStatus
CommunityMemberStatusCreator
      String
"communityMemberStatusAdministrator" -> Value -> Parser CommunityMemberStatus
parseCommunityMemberStatusAdministrator Value
v
      String
"communityMemberStatusMember"        -> CommunityMemberStatus -> Parser CommunityMemberStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CommunityMemberStatus
CommunityMemberStatusMember
      String
"communityMemberStatusLeft"          -> CommunityMemberStatus -> Parser CommunityMemberStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CommunityMemberStatus
CommunityMemberStatusLeft
      String
"communityMemberStatusBanned"        -> CommunityMemberStatus -> Parser CommunityMemberStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CommunityMemberStatus
CommunityMemberStatusBanned
      String
_                                    -> Parser CommunityMemberStatus
forall a. Monoid a => a
mempty
    
    where
      parseCommunityMemberStatusAdministrator :: A.Value -> AT.Parser CommunityMemberStatus
      parseCommunityMemberStatusAdministrator :: Value -> Parser CommunityMemberStatus
parseCommunityMemberStatusAdministrator = String
-> (Object -> Parser CommunityMemberStatus)
-> Value
-> Parser CommunityMemberStatus
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CommunityMemberStatusAdministrator" ((Object -> Parser CommunityMemberStatus)
 -> Value -> Parser CommunityMemberStatus)
-> (Object -> Parser CommunityMemberStatus)
-> Value
-> Parser CommunityMemberStatus
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Bool
can_be_edited_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"can_be_edited"
        Maybe CommunityAdministratorRights
rights_        <- Object
o Object -> Key -> Parser (Maybe CommunityAdministratorRights)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"rights"
        CommunityMemberStatus -> Parser CommunityMemberStatus
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CommunityMemberStatus -> Parser CommunityMemberStatus)
-> CommunityMemberStatus -> Parser CommunityMemberStatus
forall a b. (a -> b) -> a -> b
$ CommunityMemberStatusAdministrator
          { can_be_edited :: Maybe Bool
can_be_edited = Maybe Bool
can_be_edited_
          , rights :: Maybe CommunityAdministratorRights
rights        = Maybe CommunityAdministratorRights
rights_
          }
  parseJSON Value
_ = Parser CommunityMemberStatus
forall a. Monoid a => a
mempty