use serde::{Serialize, Deserialize};
use serde_json::Value;
use crate::{session::SessionStore, request::{RequestType}, WechatCommonResponse, LabradorResult, WechatCpClient};
use crate::wechat::cp::method::{CpAgentMethod, WechatCpMethod};
#[derive(Debug, Clone)]
pub struct WechatCpAgent<'a, T: SessionStore> {
client: &'a WechatCpClient<T>,
}
#[allow(unused)]
impl<'a, T: SessionStore> WechatCpAgent<'a, T> {
#[inline]
pub fn new(client: &WechatCpClient<T>) -> WechatCpAgent<T> {
WechatCpAgent {
client,
}
}
pub async fn get(&self, agent_id: i32) -> LabradorResult<WechatCpAgentInfo> {
let v = self.client.get(WechatCpMethod::Agent(CpAgentMethod::Get(agent_id)), vec![], RequestType::Json).await?.json::<Value>()?;
WechatCommonResponse::parse::<WechatCpAgentInfo>(v)
}
pub async fn set(&self, req: WechatCpAgentInfo) -> LabradorResult<WechatCommonResponse> {
self.client.post(WechatCpMethod::Agent(CpAgentMethod::Set), vec![], req,RequestType::Json).await?.json::<WechatCommonResponse>()
}
pub async fn list(&self) -> LabradorResult<WechatCpAgentListResponse> {
let v = self.client.get(WechatCpMethod::Agent(CpAgentMethod::List), vec![],RequestType::Json).await?.json::<Value>()?;
WechatCommonResponse::parse::<WechatCpAgentListResponse>(v)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WechatCpAgentInfo {
pub agentid: Option<i32>,
pub name: Option<String>,
pub square_logo_url: Option<String>,
pub logo_mediaid: Option<String>,
pub description: Option<String>,
pub allow_userinfos: Option<Users>,
pub allow_partys: Option<Parties>,
pub allow_tags: Option<Tags>,
pub close: Option<i32>,
pub redirect_domain: Option<String>,
pub report_location_flag: Option<i32>,
pub isreportenter: Option<i32>,
pub home_url: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Users {
pub user: Option<Vec<User>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Parties {
pub partyid: Option<Vec<i64>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Tags {
pub tagid: Option<Vec<i64>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct User {
pub userid: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WechatCpAgentListResponse {
pub agentlist: Option<Vec<WechatCpAgentInfo>>,
}