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

///|
/// Operations in the `Application` group. Implement this trait to mock or wrap `Client`.
pub(open) trait ApplicationClient {
  async fn list_account_applications(self : Self, account_id~ : @uuid.UUID) -> @model.PageApplication raise GolemError
  async fn create_application(
    self : Self,
    account_id~ : @uuid.UUID,
    body~ : @model.ApplicationCreation,
  ) -> @model.Application raise GolemError
  async fn get_account_application(
    self : Self,
    account_id~ : @uuid.UUID,
    application_name~ : String,
  ) -> @model.Application raise GolemError
  async fn get_application(self : Self, application_id~ : @uuid.UUID) -> @model.Application raise GolemError
  async fn delete_application(
    self : Self,
    application_id~ : @uuid.UUID,
    current_revision~ : UInt64,
  ) -> Unit raise GolemError
  async fn update_application(
    self : Self,
    application_id~ : @uuid.UUID,
    body~ : @model.ApplicationUpdate,
  ) -> @model.Application raise GolemError
  async fn list_application_environments(
    self : Self,
    application_id~ : @uuid.UUID,
  ) -> @model.PageEnvironment raise GolemError
  async fn create_environment(
    self : Self,
    application_id~ : @uuid.UUID,
    body~ : @model.EnvironmentCreation,
  ) -> @model.Environment raise GolemError
  async fn get_application_environment(
    self : Self,
    application_id~ : @uuid.UUID,
    environment_name~ : String,
  ) -> @model.Environment raise GolemError
}

///|
/// List all applications in the account
///
/// `GET /v1/accounts/{account_id}/apps` (`list_account_applications`).
pub impl[T : @runtime.Transport] ApplicationClient for Client[T] with fn list_account_applications(
  self : Client[T],
  account_id~ : @uuid.UUID,
) -> @model.PageApplication 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}/apps", __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.PageApplication)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// Create an application in the account
///
/// `POST /v1/accounts/{account_id}/apps` (`create_application`).
pub impl[T : @runtime.Transport] ApplicationClient for Client[T] with fn create_application(
  self : Client[T],
  account_id~ : @uuid.UUID,
  body~ : @model.ApplicationCreation,
) -> @model.Application 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}/apps", __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.Application)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// Get application in the account by name
///
/// `GET /v1/accounts/{account_id}/apps/{application_name}` (`get_account_application`).
pub impl[T : @runtime.Transport] ApplicationClient for Client[T] with fn get_account_application(
  self : Client[T],
  account_id~ : @uuid.UUID,
  application_name~ : String,
) -> @model.Application raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(("account_id", account_id.to_string()))
  __path_params.push(("application_name", application_name))
  let __path = self.expand_op_path(
    "/v1/accounts/{account_id}/apps/{application_name}", __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.Application)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// Get application by id.
///
/// `GET /v1/apps/{application_id}` (`get_application`).
pub impl[T : @runtime.Transport] ApplicationClient for Client[T] with fn get_application(
  self : Client[T],
  application_id~ : @uuid.UUID,
) -> @model.Application raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(("application_id", application_id.to_string()))
  let __path = self.expand_op_path("/v1/apps/{application_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.Application)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// Update application by id.
///
/// `DELETE /v1/apps/{application_id}` (`delete_application`).
pub impl[T : @runtime.Transport] ApplicationClient for Client[T] with fn delete_application(
  self : Client[T],
  application_id~ : @uuid.UUID,
  current_revision~ : UInt64,
) -> Unit raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(("application_id", application_id.to_string()))
  let __path = self.expand_op_path("/v1/apps/{application_id}", __path_params)
  let __qb = @encoding.QueryBuilder::new()
  let _ = __qb.add_scalar(
    "current_revision",
    @encoding.format_uint64(current_revision),
  )
  let __req = self.prepare_request(
    http_method="DELETE",
    path=__path,
    query=__qb.build(),
  )
  let __resp = self.send_request(__req)
  match __resp.status() {
    204 => ()
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// Update application by id.
///
/// `PATCH /v1/apps/{application_id}` (`update_application`).
pub impl[T : @runtime.Transport] ApplicationClient for Client[T] with fn update_application(
  self : Client[T],
  application_id~ : @uuid.UUID,
  body~ : @model.ApplicationUpdate,
) -> @model.Application raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(("application_id", application_id.to_string()))
  let __path = self.expand_op_path("/v1/apps/{application_id}", __path_params)
  let __req = self.prepare_request(http_method="PATCH", 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.Application)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// List all application environments
///
/// `GET /v1/apps/{application_id}/envs` (`list_application_environments`).
pub impl[T : @runtime.Transport] ApplicationClient for Client[T] with fn list_application_environments(
  self : Client[T],
  application_id~ : @uuid.UUID,
) -> @model.PageEnvironment raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(("application_id", application_id.to_string()))
  let __path = self.expand_op_path(
    "/v1/apps/{application_id}/envs", __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.PageEnvironment)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// Create an application environment
///
/// `POST /v1/apps/{application_id}/envs` (`create_environment`).
pub impl[T : @runtime.Transport] ApplicationClient for Client[T] with fn create_environment(
  self : Client[T],
  application_id~ : @uuid.UUID,
  body~ : @model.EnvironmentCreation,
) -> @model.Environment raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(("application_id", application_id.to_string()))
  let __path = self.expand_op_path(
    "/v1/apps/{application_id}/envs", __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.Environment)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
/// Get application environment by name
///
/// `GET /v1/apps/{application_id}/envs/{environment_name}` (`get_application_environment`).
pub impl[T : @runtime.Transport] ApplicationClient for Client[T] with fn get_application_environment(
  self : Client[T],
  application_id~ : @uuid.UUID,
  environment_name~ : String,
) -> @model.Environment raise GolemError {
  let __path_params : Array[(String, String)] = []
  __path_params.push(("application_id", application_id.to_string()))
  __path_params.push(("environment_name", environment_name))
  let __path = self.expand_op_path(
    "/v1/apps/{application_id}/envs/{environment_name}", __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.Environment)
      })
    _ => raise self.api_error_from_response(__resp)
  }
}

///|
pub extend Client with ApplicationClient::{
  list_account_applications,
  create_application,
  get_account_application,
  get_application,
  delete_application,
  update_application,
  list_application_environments,
  create_environment,
  get_application_environment,
}