use serde::ser::SerializeStruct;
use serde::{Serialize, Serializer};
use std::fmt::Debug;
use super::{JsonRpcId, JsonRpcMethod, JsonRpcParams, JsonRpcRequest, JsonRpcVersion};
#[derive(Debug)]
pub struct OdooOrmContainer<T>
where
T: OdooOrmMethod + JsonRpcParams<Container<T> = Self>,
{
pub(crate) inner: T,
}
impl<T> Serialize for OdooOrmContainer<T>
where
T: OdooOrmMethod + JsonRpcParams<Container<T> = Self>,
{
fn serialize<S>(&self, serializer: S) -> ::std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut state = serializer.serialize_struct("args", 3)?;
state.serialize_field("service", "object")?;
state.serialize_field("method", "execute_kw")?;
state.serialize_field("args", &self.inner)?;
state.end()
}
}
pub trait OdooOrmMethod
where
Self: Sized + Debug + Serialize + JsonRpcParams<Container<Self> = OdooOrmContainer<Self>>,
Self::Container<Self>: Debug + Serialize,
{
fn endpoint(&self) -> &'static str;
fn method(&self) -> &'static str;
fn _build(self, id: JsonRpcId) -> JsonRpcRequest<Self> {
JsonRpcRequest {
jsonrpc: JsonRpcVersion::V2,
method: JsonRpcMethod::Call,
id,
params: OdooOrmContainer { inner: self },
}
}
}