use golem_api_grpc::proto::golem::common;
use golem_api_grpc::proto::golem::component;
use golem_api_grpc::proto::golem::worker;
use crate::model::{
AccountId, ComponentId, IdempotencyKey, PluginInstallationId, PromiseId, WorkerId,
};
pub fn proto_component_id_string(component_id: &Option<component::ComponentId>) -> Option<String> {
(*component_id)
.and_then(|v| TryInto::<ComponentId>::try_into(v).ok())
.map(|v| v.to_string())
}
pub fn proto_worker_id_string(worker_id: &Option<worker::WorkerId>) -> Option<String> {
worker_id
.clone()
.and_then(|v| TryInto::<WorkerId>::try_into(v).ok())
.map(|v| v.to_string())
}
pub fn proto_idempotency_key_string(
idempotency_key: &Option<worker::IdempotencyKey>,
) -> Option<String> {
idempotency_key
.clone()
.map(|v| Into::<IdempotencyKey>::into(v).to_string())
}
pub fn proto_account_id_string(account_id: &Option<common::AccountId>) -> Option<String> {
account_id
.clone()
.map(|v| Into::<AccountId>::into(v).to_string())
}
pub fn proto_promise_id_string(promise_id: &Option<worker::PromiseId>) -> Option<String> {
promise_id
.clone()
.and_then(|v| TryInto::<PromiseId>::try_into(v).ok())
.map(|v| v.to_string())
}
pub fn proto_plugin_installation_id_string(
component_id: &Option<common::PluginInstallationId>,
) -> Option<String> {
(*component_id)
.and_then(|v| TryInto::<PluginInstallationId>::try_into(v).ok())
.map(|v| v.to_string())
}
pub fn proto_invocation_context_parent_worker_id_string(
invocation_context: &Option<worker::InvocationContext>,
) -> Option<String> {
proto_worker_id_string(&invocation_context.as_ref().and_then(|c| c.parent.clone()))
}
pub enum ProtoApiDefinitionKind {
Golem,
OpenAPI,
}