-- |
-- The Owner teams API as described on
-- <http://developer.github.com/v3/orgs/teams/>.

module GitHub.Endpoints.Organizations.Teams (
    teamsOfR,
    teamInfoForR,
    createTeamForR,
    editTeamR,
    deleteTeamR,
    listTeamMembersR,
    listTeamReposR,
    addOrUpdateTeamRepoR,
    teamMembershipInfoForR,
    addTeamMembershipForR,
    deleteTeamMembershipForR,
    listTeamsCurrentR,
    module GitHub.Data,
    ) where

import GitHub.Data
import GitHub.Internal.Prelude
import Prelude ()

-- | List teams.
-- See <https://developer.github.com/v3/orgs/teams/#list-teams>
teamsOfR :: Name Organization -> FetchCount -> Request k (Vector SimpleTeam)
teamsOfR :: forall (k :: RW).
Name Organization -> FetchCount -> Request k (Vector SimpleTeam)
teamsOfR Name Organization
org =
    Paths -> QueryString -> FetchCount -> Request k (Vector SimpleTeam)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"orgs", Name Organization -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Organization
org, Text
"teams"] []

-- | Query team.
-- See <https://developer.github.com/v3/orgs/teams/#get-team>
teamInfoForR  :: Id Team -> Request k Team
teamInfoForR :: forall (k :: RW). Id Team -> Request k Team
teamInfoForR Id Team
tid =
    Paths -> QueryString -> Request k Team
forall (mt :: RW) a. Paths -> QueryString -> Request mt a
query [Text
"teams", Id Team -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Team
tid] []

-- | Create team.
-- See <https://developer.github.com/v3/orgs/teams/#create-team>
createTeamForR :: Name Organization -> CreateTeam -> Request 'RW Team
createTeamForR :: Name Organization -> CreateTeam -> Request 'RW Team
createTeamForR Name Organization
org CreateTeam
cteam =
    CommandMethod -> Paths -> ByteString -> Request 'RW Team
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Post [Text
"orgs", Name Organization -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Organization
org, Text
"teams"] (CreateTeam -> ByteString
forall a. ToJSON a => a -> ByteString
encode CreateTeam
cteam)

-- | Edit team.
-- See <https://developer.github.com/v3/orgs/teams/#edit-team>
editTeamR :: Id Team -> EditTeam -> Request 'RW Team
editTeamR :: Id Team -> EditTeam -> Request 'RW Team
editTeamR Id Team
tid EditTeam
eteam =
    CommandMethod -> Paths -> ByteString -> Request 'RW Team
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Patch [Text
"teams", Id Team -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Team
tid] (EditTeam -> ByteString
forall a. ToJSON a => a -> ByteString
encode EditTeam
eteam)

--
-- See <https://developer.github.com/v3/orgs/teams/#delete-team>
deleteTeamR :: Id Team -> GenRequest 'MtUnit 'RW ()
deleteTeamR :: Id Team -> GenRequest 'MtUnit 'RW ()
deleteTeamR Id Team
tid =
    CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType (*)) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Delete [Text
"teams", Id Team -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Team
tid] ByteString
forall a. Monoid a => a
mempty

-- | List team members.
--
-- See <https://developer.github.com/v3/orgs/teams/#list-team-members>
listTeamMembersR :: Id Team -> TeamMemberRole -> FetchCount -> Request 'RA (Vector SimpleUser)
listTeamMembersR :: Id Team
-> TeamMemberRole -> FetchCount -> Request 'RA (Vector SimpleUser)
listTeamMembersR Id Team
tid TeamMemberRole
r =
    Paths
-> QueryString -> FetchCount -> Request 'RA (Vector SimpleUser)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"teams", Id Team -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Team
tid, Text
"members"] [(ByteString
"role", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
r')]
  where
    r' :: ByteString
r' = case TeamMemberRole
r of
        TeamMemberRole
TeamMemberRoleAll         -> ByteString
"all"
        TeamMemberRole
TeamMemberRoleMaintainer  -> ByteString
"maintainer"
        TeamMemberRole
TeamMemberRoleMember      -> ByteString
"member"

-- | Query team repositories.
-- See <https://developer.github.com/v3/orgs/teams/#list-team-repos>
listTeamReposR :: Id Team -> FetchCount -> Request k (Vector Repo)
listTeamReposR :: forall (k :: RW). Id Team -> FetchCount -> Request k (Vector Repo)
listTeamReposR Id Team
tid  =
    Paths -> QueryString -> FetchCount -> Request k (Vector Repo)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"teams", Id Team -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Team
tid, Text
"repos"] []

-- | Add or update a team repository.
-- See <https://developer.github.com/v3/orgs/teams/#add-or-update-team-repository>
addOrUpdateTeamRepoR :: Id Team -> Name Organization -> Name Repo -> Permission -> GenRequest 'MtUnit 'RW ()
addOrUpdateTeamRepoR :: Id Team
-> Name Organization
-> Name Repo
-> Permission
-> GenRequest 'MtUnit 'RW ()
addOrUpdateTeamRepoR Id Team
tid Name Organization
org Name Repo
repo Permission
permission =
    CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType (*)) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Put [Text
"teams", Id Team -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Team
tid, Text
"repos", Name Organization -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Organization
org, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo] (AddTeamRepoPermission -> ByteString
forall a. ToJSON a => a -> ByteString
encode (AddTeamRepoPermission -> ByteString)
-> AddTeamRepoPermission -> ByteString
forall a b. (a -> b) -> a -> b
$ Permission -> AddTeamRepoPermission
AddTeamRepoPermission Permission
permission)

-- | Query team membership.
-- See <https://developer.github.com/v3/orgs/teams/#get-team-membership
teamMembershipInfoForR :: Id Team -> Name Owner -> Request k TeamMembership
teamMembershipInfoForR :: forall (k :: RW). Id Team -> Name Owner -> Request k TeamMembership
teamMembershipInfoForR Id Team
tid Name Owner
user =
    Paths -> QueryString -> Request k TeamMembership
forall (mt :: RW) a. Paths -> QueryString -> Request mt a
query [Text
"teams", Id Team -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Team
tid, Text
"memberships", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user] []

-- | Add team membership.
-- See <https://developer.github.com/v3/orgs/teams/#add-team-membership>
addTeamMembershipForR :: Id Team -> Name Owner -> Role -> Request 'RW TeamMembership
addTeamMembershipForR :: Id Team -> Name Owner -> Role -> Request 'RW TeamMembership
addTeamMembershipForR Id Team
tid Name Owner
user Role
role =
    CommandMethod -> Paths -> ByteString -> Request 'RW TeamMembership
forall a. CommandMethod -> Paths -> ByteString -> Request 'RW a
command CommandMethod
Put [Text
"teams", Id Team -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Team
tid, Text
"memberships", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user] (CreateTeamMembership -> ByteString
forall a. ToJSON a => a -> ByteString
encode (CreateTeamMembership -> ByteString)
-> CreateTeamMembership -> ByteString
forall a b. (a -> b) -> a -> b
$ Role -> CreateTeamMembership
CreateTeamMembership Role
role)

-- | Remove team membership.
-- See <https://developer.github.com/v3/orgs/teams/#remove-team-membership>
deleteTeamMembershipForR :: Id Team -> Name Owner -> GenRequest 'MtUnit 'RW ()
deleteTeamMembershipForR :: Id Team -> Name Owner -> GenRequest 'MtUnit 'RW ()
deleteTeamMembershipForR Id Team
tid Name Owner
user =
    CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType (*)) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Delete [Text
"teams", Id Team -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Team
tid, Text
"memberships", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user] ByteString
forall a. Monoid a => a
mempty

-- | List user teams.
-- See <https://developer.github.com/v3/orgs/teams/#list-user-teams>
listTeamsCurrentR :: FetchCount -> Request 'RA (Vector Team)
listTeamsCurrentR :: FetchCount -> Request 'RA (Vector Team)
listTeamsCurrentR =
    Paths -> QueryString -> FetchCount -> Request 'RA (Vector Team)
forall a (mt :: RW).
FromJSON a =>
Paths -> QueryString -> FetchCount -> Request mt (Vector a)
pagedQuery [Text
"user", Text
"teams"] []