use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use num_enum::TryFromPrimitive;
use crate::{
taxonomy::*, CallError, Entity, InvalidResponse, Session, SessionAsync, SessionTrait,
String255, Token, Value,
};
use crate::session::api::macros::*;
decl_call! {
InsertFactor(entity: Entity, attribute: Attribute, name: String255, key: String255, value: Value, authorization: Token) -> (),
{
index: i64,
offset: i32,
instance: i32,
deferred: bool,
}
}
impl<T: SessionTrait> InsertFactor<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Insert, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_value(&self.value)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
RemoveFactor(entity: Entity, attribute: Attribute, name: String255, index: i64, authorization: Token) -> (),
{
instance: i32,
offset: i32,
deferred: bool,
}
}
impl<T: SessionTrait> RemoveFactor<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Remove, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
ReplaceFactor(entity: Entity, attribute: Attribute, name: String255, key: String255, value: Value, authorization: Token) -> (),
{
offset: i32,
instance: i32,
index: i64,
deferred: bool,
}
}
impl<T: SessionTrait> ReplaceFactor<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Replace, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_value(&self.value)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
FindFactor(entity: Entity, attribute: Attribute, name: String255, value: Value, authorization: Token) -> i64,
{
offset: i32,
instance: i32,
index: i64,
}
}
impl<T: SessionTrait> FindFactor<T> {
async fn call_async(self) -> Result<i64, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Find, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_value(&self.value)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.await?;
Ok(res.integer()?)
}
}
decl_call! {
IncludeFactor(entity: Entity, attribute: Attribute, name: String255, key: String255, value: Value, authorization: Token) -> (),
{
deferred: bool,
}
}
impl<T: SessionTrait> IncludeFactor<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Include, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_value(&self.value)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
ExcludeFactor(entity: Entity, attribute: Attribute, name: String255, key: String255, authorization: Token) -> (),
{
deferred: bool,
}
}
impl<T: SessionTrait> ExcludeFactor<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Exclude, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
SetFactor(entity: Entity, attribute: Attribute, name: String255, key: String255, value: Value, authorization: Token) -> (),
{
deferred: bool,
}
}
impl<T: SessionTrait> SetFactor<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Set, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_value(&self.value)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
GetFactor(entity: Entity, attribute: Attribute, name: String255, key: String255, authorization: Token) -> Value,
{
}
}
impl<T: SessionTrait> GetFactor<T> {
async fn call_async(self) -> Result<Value, CallError> {
self.session
.get_async_session()
.invoke_entity(self.entity, Method::Get, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.await
}
}
decl_call! {
ClearFactor(entity: Entity, attribute: Attribute, name: String255, key: String255, authorization: Token) -> (),
{
deferred: bool,
}
}
impl<T: SessionTrait> ClearFactor<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Clear, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
FactorCount(entity: Entity, attribute: Attribute, name: String255, authorization: Token) -> i64,
{
offset: i32,
instance: i32,
}
}
impl<T: SessionTrait> FactorCount<T> {
async fn call_async(self) -> Result<i64, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Count, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_instance(self.instance)
.with_offset(self.offset)
.await?;
Ok(res.integer()?)
}
}
decl_call! {
FactorMember(entity: Entity, attribute: Attribute, name: String255, key: String255, authorization: Token) -> bool,
{
offset: i32,
instance: i32,
}
}
impl<T: SessionTrait> FactorMember<T> {
async fn call_async(self) -> Result<bool, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Member, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_instance(self.instance)
.with_offset(self.offset)
.await?;
Ok(res.boolean()?)
}
}
decl_call! {
FactorName(entity: Entity, authorization: Token) -> String255,
{
attribute: Attribute,
key: String255,
index: i64,
instance: i32,
offset: i32,
}
}
impl<T: SessionTrait> FactorName<T> {
async fn call_async(self) -> Result<String255, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Name, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_key(self.key)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.await?;
Ok(res
.string()?
.try_into()
.map_err(|e| CallError::InvalidResponse(InvalidResponse::Name(e)))?)
}
}
decl_call! {
FactorKey(entity: Entity, attribute: Attribute, name: String255, index: i64, authorization: Token) -> String255,
{
instance: i32,
offset: i32,
}
}
impl<T: SessionTrait> FactorKey<T> {
async fn call_async(self) -> Result<String255, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Key, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.await?;
Ok(res
.string()?
.try_into()
.map_err(|e| CallError::InvalidResponse(InvalidResponse::Key(e)))?)
}
}
decl_call! {
FactorValue(entity: Entity, attribute: Attribute, name: String255, key: String255, authorization: Token) -> Value,
{
index: i64,
instance: i32,
offset: i32,
}
}
impl<T: SessionTrait> FactorValue<T> {
async fn call_async(self) -> Result<Value, CallError> {
self.session
.get_async_session()
.invoke_entity(self.entity, Method::Value, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.await
}
}
decl_call! {
FactorIndex(entity: Entity, attribute: Attribute, name: String255, key: String255, authorization: Token) -> i64,
{
instance: i32,
offset: i32,
}
}
impl<T: SessionTrait> FactorIndex<T> {
async fn call_async(self) -> Result<i64, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Index, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_key(self.key)
.with_instance(self.instance)
.with_offset(self.offset)
.await?;
Ok(res.integer()?)
}
}
decl_call! {
FactorAttribute(entity: Entity, authorization: Token) -> Attribute,
{
name: String255,
key: String255,
offset: i32,
instance: i32,
index: i64,
}
}
impl<T: SessionTrait> FactorAttribute<T> {
async fn call_async(self) -> Result<Attribute, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Attribute, self.authorization)
.with_aspect(Aspect::Factor)
.with_name(self.name)
.with_key(self.key)
.with_index(self.index)
.with_instance(self.instance)
.with_offset(self.offset)
.await?;
let num64 = res.integer()?;
let num16 = u16::try_from(num64).map_err(|_| InvalidResponse::Attribute(num64))?;
let attr =
Attribute::try_from_primitive(num16).map_err(|_| InvalidResponse::Attribute(num64))?;
Ok(attr)
}
}
decl_call! {
SortFactors(entity: Entity, attribute: Attribute, name: String255, authorization: Token) -> (),
{
offset: i32,
instance: i32,
deferred: bool,
}
}
impl<T: SessionTrait> SortFactors<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Sort, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_instance(self.instance)
.with_offset(self.offset)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
PurgeFactors(entity: Entity, attribute: Attribute, name: String255, authorization: Token) -> (),
{
offset: i32,
instance: i32,
deferred: bool,
}
}
impl<T: SessionTrait> PurgeFactors<T> {
async fn call_async(self) -> Result<(), CallError> {
let _ = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Purge, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_instance(self.instance)
.with_offset(self.offset)
.with_parameter(self.deferred as i64)
.await?;
Ok(())
}
}
decl_call! {
RetrieveFactors(entity: Entity, attribute: Attribute, name: String255, authorization: Token) -> String,
{
offset: i32,
instance: i32,
}
}
impl<T: SessionTrait> RetrieveFactors<T> {
async fn call_async(self) -> Result<String, CallError> {
let res = self
.session
.get_async_session()
.invoke_entity(self.entity, Method::Retrieve, self.authorization)
.with_aspect(Aspect::Factor)
.with_attribute(self.attribute)
.with_name(self.name)
.with_instance(self.instance)
.with_offset(self.offset)
.await?;
Ok(res.interchange()?)
}
}