{-# LANGUAGE DataKinds         #-}
{-# LANGUAGE OverloadedStrings #-}
module GitHub.Paths.Orgs.Teams where

import           Data.Aeson            (Value, encode)
import           Data.Text             (Text)
import qualified Data.Text             as Text
import           Data.Vector           (Vector)
import           GitHub.Data.Request   (CommandMethod (Delete, Patch, Post),
                                        FetchCount (FetchAll), RW (..), Request,
                                        command, pagedQuery)
import           GitHub.Types.Settings (Team)

getTeamsR :: Text -> Request 'RO (Vector Team)
getTeamsR :: Text -> Request 'RO (Vector Team)
getTeamsR Text
org =
    Paths -> QueryString -> FetchCount -> Request 'RO (Vector Team)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"orgs", Text
org, Text
"teams"] [] FetchCount
FetchAll

createTeamR :: Text -> Team -> Request 'RW Value
createTeamR :: Text -> Team -> Request 'RW Value
createTeamR Text
org =
    CommandMethod -> Paths -> ByteString -> Request 'RW Value
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Post [Text
"orgs", Text
org, Text
"teams"] (ByteString -> Request 'RW Value)
-> (Team -> ByteString) -> Team -> Request 'RW Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Team -> ByteString
forall a. ToJSON a => a -> ByteString
encode

updateTeamR :: Text -> Text -> Team -> Request 'RW Value
updateTeamR :: Text -> Text -> Team -> Request 'RW Value
updateTeamR Text
org Text
team =
    CommandMethod -> Paths -> ByteString -> Request 'RW Value
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Patch [Text
"orgs", Text
org, Text
"teams", Text
team] (ByteString -> Request 'RW Value)
-> (Team -> ByteString) -> Team -> Request 'RW Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Team -> ByteString
forall a. ToJSON a => a -> ByteString
encode

deleteTeamR :: Text -> Int -> Request 'RW Value
deleteTeamR :: Text -> Int -> Request 'RW Value
deleteTeamR Text
org Int
teamId =
    CommandMethod -> Paths -> ByteString -> Request 'RW Value
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Delete [Text
"orgs", Text
org, Text
"teams", String -> Text
Text.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Int -> String
forall a. Show a => a -> String
show Int
teamId] ByteString
forall a. Monoid a => a
mempty