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

///|
/// Operations in the `Card` group. Implement this trait to mock or wrap `Client`.
pub(open) trait CardClient {
  async fn list_account_cards(
    self : Self,
    account_id~ : @uuid.UUID,
    include_root? : Bool,
    include_permission_shares? : Bool,
    include_environment_defaults? : Bool,
    include_agent_initials? : Bool,
  ) -> Array[@model.StoredCard] raise GolemError
  async fn get_card(self : Self, card_id~ : @uuid.UUID) -> @model.StoredCard raise GolemError
  async fn revoke_card(self : Self, card_id~ : @uuid.UUID) -> @model.RevokedCardsResponse raise GolemError
}

///|
/// List cards owned by an account.
///
/// `GET /v1/accounts/{account_id}/cards` (`list_account_cards`).
pub impl[T : @runtime.Transport] CardClient for Client[T] with fn list_account_cards(
  self : Client[T],
  account_id~ : @uuid.UUID,
  include_root? : Bool,
  include_permission_shares? : Bool,
  include_environment_defaults? : Bool,
  include_agent_initials? : Bool,
) -> Array[@model.StoredCard] raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(("account_id", account_id.to_string()))
  let __path = self.expand_op_path(
    "/v1/accounts/{account_id}/cards", __path_params,
  )
  let __qb = @encoding.QueryBuilder::new()
  match include_root {
    Option::Some(__qv) => {
      let _ = __qb.add_scalar("include_root", @encoding.format_bool(__qv))
    }
    Option::None => ()
  }
  match include_permission_shares {
    Option::Some(__qv) => {
      let _ = __qb.add_scalar(
        "include_permission_shares",
        @encoding.format_bool(__qv),
      )
    }
    Option::None => ()
  }
  match include_environment_defaults {
    Option::Some(__qv) => {
      let _ = __qb.add_scalar(
        "include_environment_defaults",
        @encoding.format_bool(__qv),
      )
    }
    Option::None => ()
  }
  match include_agent_initials {
    Option::Some(__qv) => {
      let _ = __qb.add_scalar(
        "include_agent_initials",
        @encoding.format_bool(__qv),
      )
    }
    Option::None => ()
  }
  let __req = self.prepare_request(
    http_method="GET",
    path=__path,
    query=__qb.build(),
  )
  let __resp = self.send_request(__req)
  match __resp.status() {
    200 =>
      self.decode_json_response(__resp, __r => {
        __r
        .read_array()
        .map(__el_0 => {
          (
            @cjson.FromJson::from_json(__el_0.raw(), __el_0.context()) :
            @model.StoredCard)
        })
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// Get a card by id.
///
/// `GET /v1/cards/{card_id}` (`get_card`).
pub impl[T : @runtime.Transport] CardClient for Client[T] with fn get_card(
  self : Client[T],
  card_id~ : @uuid.UUID,
) -> @model.StoredCard raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(("card_id", card_id.to_string()))
  let __path = self.expand_op_path("/v1/cards/{card_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.StoredCard)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// Revoke a card and all of its descendants.
///
/// `DELETE /v1/cards/{card_id}` (`revoke_card`).
pub impl[T : @runtime.Transport] CardClient for Client[T] with fn revoke_card(
  self : Client[T],
  card_id~ : @uuid.UUID,
) -> @model.RevokedCardsResponse raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(("card_id", card_id.to_string()))
  let __path = self.expand_op_path("/v1/cards/{card_id}", __path_params)
  let __req = self.prepare_request(http_method="DELETE", 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.RevokedCardsResponse)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
pub extend Client with CardClient::{list_account_cards, get_card, revoke_card}