use super::post_send;
use crate::{wechat::WxApiRequestBuilder, SdkResult};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Serialize, Deserialize)]
pub struct ApplyList {
pub apply_list: Vec<ApplyItem>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ApplyItem {
pub appid: String,
pub status: i32,
pub nickname: String,
pub headimgurl: String,
pub categories: Vec<HashMap<String, String>>,
pub create_time: String,
pub apply_url: String,
pub reason: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PluginList {
pub plugin_list: Vec<PluginItem>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PluginItem {
pub appid: String,
pub status: i32,
pub nickname: String,
pub headimgurl: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SetDevPluginStatus {
pub action: SetAction,
#[serde(default)]
pub appid: Option<String>,
#[serde(default)]
pub reason: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SetAction {
DevAgree,
DevRefuse,
DevDelete,
}
pub struct PluginManageModule<'a, T: WxApiRequestBuilder>(pub(crate) &'a T);
impl<'a, T: WxApiRequestBuilder> PluginManageModule<'a, T> {
pub async fn apply_plugin(&self, plugin_appid: &str, reason: Option<String>) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxa/plugin";
let data = &serde_json::json!({
"action": "apply",
"plugin_appid": plugin_appid,
"reason": reason,
});
post_send(self.0, url, data).await
}
pub async fn get_plugin_dev_apply_list(&self, page: i32, num: i32) -> SdkResult<ApplyList> {
let url = "https://api.weixin.qq.com/wxa/devplugin";
let data = &serde_json::json!({
"action": "dev_apply_list",
"page": page,
"num": num,
});
post_send(self.0, url, data).await
}
pub async fn get_plugin_list(&self) -> SdkResult<PluginList> {
let url = "https://api.weixin.qq.com/wxa/plugin";
post_send(self.0, url, &serde_json::json!({"action": "list"})).await
}
pub async fn set_dev_plugin_apply_status(&self, data: &SetDevPluginStatus) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxa/devplugin";
post_send(self.0, url, data).await
}
pub async fn unbind_plugin(&self, plugin_appid: &str) -> SdkResult<()> {
let url = "https://api.weixin.qq.com/wxa/plugin";
let data = &serde_json::json!({"action": "unbind", "plugin_appid": plugin_appid});
post_send(self.0, url, data).await
}
}