use std::marker::PhantomData;
use super::*;
pub struct CopilotSeatHandler<'octo, 'r> {
crab: &'octo Octocrab,
owner: String,
_phantom: PhantomData<&'r ()>,
}
#[derive(serde::Serialize)]
struct SelectedTeams {
selected_teams: Vec<String>,
}
#[derive(serde::Serialize)]
struct SelectedUsernames {
selected_usernames: Vec<String>,
}
impl<'octo, 'r> CopilotSeatHandler<'octo, 'r> {
pub fn new(handler: &'r OrgHandler<'octo>) -> Self {
Self {
crab: handler.crab,
owner: handler.owner.clone(),
_phantom: PhantomData,
}
}
pub(crate) fn new_with_owner(crab: &'octo Octocrab, owner: String) -> Self {
Self {
crab,
owner,
_phantom: PhantomData,
}
}
pub async fn add_teams(
self,
teams: Vec<String>,
) -> crate::Result<crate::models::orgs_copilot::billing::SeatsCreated> {
let route = format!(
"/orgs/{org}/copilot/billing/selected_teams",
org = self.owner,
);
let teams = SelectedTeams {
selected_teams: teams,
};
self.crab.post(route, Some(&teams)).await
}
pub async fn remove_teams(
self,
teams: Vec<String>,
) -> crate::Result<crate::models::orgs_copilot::billing::SeatsCancelled> {
let route = format!(
"/orgs/{org}/copilot/billing/selected_teams",
org = self.owner,
);
let teams = SelectedTeams {
selected_teams: teams,
};
self.crab.delete(route, Some(&teams)).await
}
pub async fn add_usernames(
self,
usernames: Vec<String>,
) -> crate::Result<crate::models::orgs_copilot::billing::SeatsCreated> {
let route = format!(
"/orgs/{org}/copilot/billing/selected_users",
org = self.owner,
);
let usernames = SelectedUsernames {
selected_usernames: usernames,
};
self.crab.post(route, Some(&usernames)).await
}
pub async fn remove_usernames(
self,
usernames: Vec<String>,
) -> crate::Result<crate::models::orgs_copilot::billing::SeatsCancelled> {
let route = format!(
"/orgs/{org}/copilot/billing/selected_users",
org = self.owner,
);
let usernames = SelectedUsernames {
selected_usernames: usernames,
};
self.crab.delete(route, Some(&usernames)).await
}
pub async fn get_user(
&self,
username: impl AsRef<str>,
) -> crate::Result<crate::models::orgs_copilot::billing::CopilotSeat> {
let route = format!(
"/orgs/{org}/members/{username}/copilot",
org = self.owner,
username = username.as_ref(),
);
self.crab.get(route, None::<&()>).await
}
pub async fn seat_assignment(
&self,
username: impl AsRef<str>,
) -> crate::Result<crate::models::orgs_copilot::billing::CopilotSeat> {
self.get_user(username).await
}
}