import { setResources, setConfigs } from "@/store/common";
import { API_DEL_SESSION, API_GLOBAL_CONFIGS, API_STATIC_RESOURCES, API_UPLOAD_SESSION } from "./http/api";
import { request } from "./http/request";
import Taro from "@tarojs/taro";


export const staticResources = () => (dispatch: any) => {
    request({
        url: API_STATIC_RESOURCES, method: 'GET', data: {}
    }).then(res => {
        // resolve(res);
        dispatch(setResources(res));
    })

}

export const gobalConfigs = () => (dispatch: any) => {
    request({
        url: API_GLOBAL_CONFIGS, method: 'GET', data: {
            keys: 'time_duration'
        }
    }).then(res => {
        // resolve(res);
        dispatch(setConfigs(res));
    })
}

export const uploadSessionKey = (params) => {
    request({
        url: API_UPLOAD_SESSION, method: 'POST', data: {
            ...params
        }
    }).then(res => {
    })
}

export const delSession = (params) => {
    request({
        url: API_DEL_SESSION + '?type=WX_MP', method: 'DELETE', data: {
            ...params
        }
    }).then(_ => {
        Taro.showToast({
            title: '重置成功',
            icon: 'success',
            duration: 2000
        })
    })
}