use crate::{
dto::template::{
TemplateChunkSetInfoResponse, TemplateManifestInput, WasmStoreCatalogEntryResponse,
WasmStoreStatusResponse,
},
ids::{TemplateId, TemplateVersion, WasmStoreBinding},
ops::storage::{state::subnet::SubnetStateOps, template::TemplateChunkedOps},
};
use canic_core::cdk::types::Principal;
use canic_core::control_plane_support::{error::InternalError, ops::cost_guard::CostGuardPermit};
use super::super::WasmStoreInternalClient;
use super::error::PublicationWorkflowError;
pub(super) async fn store_catalog(
_publication_permit: &CostGuardPermit,
store_pid: Principal,
) -> Result<Vec<WasmStoreCatalogEntryResponse>, InternalError> {
WasmStoreInternalClient::new(store_pid).catalog().await
}
pub(super) async fn store_chunk_set_info(
_publication_permit: &CostGuardPermit,
store_pid: Principal,
template_id: &TemplateId,
version: &TemplateVersion,
) -> Result<TemplateChunkSetInfoResponse, InternalError> {
WasmStoreInternalClient::new(store_pid)
.info(template_id, version)
.await
}
pub(super) async fn store_status(
store_pid: Principal,
) -> Result<WasmStoreStatusResponse, InternalError> {
WasmStoreInternalClient::new(store_pid).status().await
}
pub(super) async fn store_stage_manifest(
publication_permit: &CostGuardPermit,
store_pid: Principal,
request: TemplateManifestInput,
) -> Result<(), InternalError> {
WasmStoreInternalClient::new(store_pid)
.stage_manifest(publication_permit, request)
.await
}
pub(super) async fn store_prepare_gc(store_pid: Principal) -> Result<(), InternalError> {
WasmStoreInternalClient::new(store_pid).prepare_gc().await
}
pub(super) async fn store_begin_gc(store_pid: Principal) -> Result<(), InternalError> {
WasmStoreInternalClient::new(store_pid).begin_gc().await
}
pub(super) async fn store_complete_gc(store_pid: Principal) -> Result<(), InternalError> {
WasmStoreInternalClient::new(store_pid).complete_gc().await
}
pub(super) async fn store_chunk(
_publication_permit: &CostGuardPermit,
store_pid: Principal,
template_id: &TemplateId,
version: &TemplateVersion,
chunk_index: u32,
) -> Result<Vec<u8>, InternalError> {
WasmStoreInternalClient::new(store_pid)
.chunk(template_id, version, chunk_index)
.await
}
pub(super) fn store_binding_for_pid(
store_pid: Principal,
) -> Result<WasmStoreBinding, InternalError> {
SubnetStateOps::wasm_store_binding_for_pid(store_pid)
.ok_or_else(|| PublicationWorkflowError::StoreNotRegistered(store_pid).into())
}
pub(super) fn local_chunk(
template_id: &TemplateId,
version: &TemplateVersion,
chunk_index: u32,
) -> Result<Vec<u8>, InternalError> {
let response = TemplateChunkedOps::chunk_response(template_id, version, chunk_index)?;
Ok(response.bytes)
}