// Generated by openapi-moonbit — DO NOT EDIT
// Spec SHA-256: 7e574664c0f434e52021e12f313a3266fd3175fe2ecddde4c0e0930549c72ba2

///|
/// Operations in the `EnvironmentPluginGrants` group. Implement this trait to mock or wrap `Client`.
pub(open) trait EnvironmentPluginGrantsClient {
  async fn list_environment_plugin_grants(
    self : Self,
    environment_id~ : @uuid.UUID,
  ) -> @model.PageEnvironmentPluginGrantWithDetails raise GolemError
  async fn create_environment_plugin_grant(
    self : Self,
    environment_id~ : @uuid.UUID,
    body~ : @model.EnvironmentPluginGrantCreation,
  ) -> @model.EnvironmentPluginGrant raise GolemError
  async fn get_environment_plugin_grant(
    self : Self,
    environment_plugin_grant_id~ : @uuid.UUID,
  ) -> @model.EnvironmentPluginGrantWithDetails raise GolemError
  async fn delete_environment_plugin_grant(
    self : Self,
    environment_plugin_grant_id~ : @uuid.UUID,
  ) -> Unit raise GolemError
}

///|
/// List all environment plugin grants in the environment
///
/// `GET /v1/envs/{environment_id}/plugins` (`list_environment_environment_plugin_grants`).
pub impl[T : @runtime.Transport] EnvironmentPluginGrantsClient for Client[T] with fn list_environment_plugin_grants(
  self : Client[T],
  environment_id~ : @uuid.UUID,
) -> @model.PageEnvironmentPluginGrantWithDetails raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(("environment_id", environment_id.to_string()))
  let __path = self.expand_op_path(
    "/v1/envs/{environment_id}/plugins", __path_params,
  )
  let __req = self.prepare_request(http_method="GET", path=__path)
  let __resp = self.send_request(__req)
  match __resp.status() {
    200 =>
      self.decode_json_response(__resp, __r => {
        (
          @cjson.FromJson::from_json(__r.raw(), __r.context()) :
          @model.PageEnvironmentPluginGrantWithDetails)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// Create a new environment plugin grant
///
/// `POST /v1/envs/{environment_id}/plugins` (`create_environment_plugin_grant`).
pub impl[T : @runtime.Transport] EnvironmentPluginGrantsClient for Client[T] with fn create_environment_plugin_grant(
  self : Client[T],
  environment_id~ : @uuid.UUID,
  body~ : @model.EnvironmentPluginGrantCreation,
) -> @model.EnvironmentPluginGrant raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(("environment_id", environment_id.to_string()))
  let __path = self.expand_op_path(
    "/v1/envs/{environment_id}/plugins", __path_params,
  )
  let __req = self.prepare_request(http_method="POST", path=__path)
  let _ = __req.with_body(
    content_type="application/json",
    body=@runtime.utf8_encode(body.to_json().stringify()),
  )
  let __resp = self.send_request(__req)
  match __resp.status() {
    200 =>
      self.decode_json_response(__resp, __r => {
        (
          @cjson.FromJson::from_json(__r.raw(), __r.context()) :
          @model.EnvironmentPluginGrant)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// Get environment plugin grant by id
///
/// `GET /v1/environment-plugins/{environment_plugin_grant_id}` (`get_environment_plugin_grant`).
pub impl[T : @runtime.Transport] EnvironmentPluginGrantsClient for Client[T] with fn get_environment_plugin_grant(
  self : Client[T],
  environment_plugin_grant_id~ : @uuid.UUID,
) -> @model.EnvironmentPluginGrantWithDetails raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(
    ("environment_plugin_grant_id", environment_plugin_grant_id.to_string()),
  )
  let __path = self.expand_op_path(
    "/v1/environment-plugins/{environment_plugin_grant_id}", __path_params,
  )
  let __req = self.prepare_request(http_method="GET", path=__path)
  let __resp = self.send_request(__req)
  match __resp.status() {
    200 =>
      self.decode_json_response(__resp, __r => {
        (
          @cjson.FromJson::from_json(__r.raw(), __r.context()) :
          @model.EnvironmentPluginGrantWithDetails)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// Delete environment plugin grant
///
/// `DELETE /v1/environment-plugins/{environment_plugin_grant_id}` (`delete_environment_plugin_grant`).
pub impl[T : @runtime.Transport] EnvironmentPluginGrantsClient for Client[T] with fn delete_environment_plugin_grant(
  self : Client[T],
  environment_plugin_grant_id~ : @uuid.UUID,
) -> Unit raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(
    ("environment_plugin_grant_id", environment_plugin_grant_id.to_string()),
  )
  let __path = self.expand_op_path(
    "/v1/environment-plugins/{environment_plugin_grant_id}", __path_params,
  )
  let __req = self.prepare_request(http_method="DELETE", path=__path)
  let __resp = self.send_request(__req)
  match __resp.status() {
    204 => ()
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
pub extend Client with EnvironmentPluginGrantsClient::{
  list_environment_plugin_grants,
  create_environment_plugin_grant,
  get_environment_plugin_grant,
  delete_environment_plugin_grant,
}