use reqwest::Method;

use super::Client;
use crate::error::Error;
use crate::types::{
    GithubAppInfo, GithubInstallationTokenPayload, GithubInstallationTokenResponse,
    GithubUserInstallationsResponse, GithubUserTokenResponse,
};

impl Client {
    pub async fn github_installation_token(
        &self,
        payload: GithubInstallationTokenPayload,
    ) -> Result<GithubInstallationTokenResponse, Error> {
        self.do_request::<_, GithubInstallationTokenResponse>(
            Method::POST,
            "/api/me/github/installation-token",
            Some(&payload),
        )
        .await
    }

    pub async fn github_user_token(&self) -> Result<GithubUserTokenResponse, Error> {
        self.do_request::<_, GithubUserTokenResponse>(
            Method::GET,
            "/api/me/github/user-token",
            None::<&()>,
        )
        .await
    }

    pub async fn me_github_installations(&self) -> Result<GithubUserInstallationsResponse, Error> {
        self.do_request::<_, GithubUserInstallationsResponse>(
            Method::GET,
            "/api/me/github/installations",
            None::<&()>,
        )
        .await
    }

    /// GET /api/v1/github/app - public GitHub App metadata (slug + install URL).
    pub async fn github_app_info(&self) -> Result<GithubAppInfo, Error> {
        self.get_public::<GithubAppInfo>("/api/v1/github/app").await
    }
}
