
import { defHttp } from '/@/utils/http/axios';
import { session } from "/@/utils/Memory.js";
import type { ErrorMessageMode } from '/#/axios';

enum Api {
    CallProvider = '/callProvider',
    List = '/base-center/system/selectSystem',
    GetUserArr = '/user-center/user/getUserArr',
    Save = '/base-center/system/saveSystem',
    Delete = '/base-center/system/deleteSystem',
}

const client = {
    grant_type: "password",
    scope: "all",
    client_id: "space",
    client_secret: 'e10adc3949ba59abbe56e057f20f883e',
}

const interfaceType = { apiUrl2: true };

/**
 * @description:获取应用列表
 */
export function list(data) {
    var params = {
        keyStr: data?.keyStr || "",
        page: 1,
        rows: 1000
    }
    return new Promise<void>((resolve, reject) => {
        defHttp.post({ url: Api.List, params })
            .then((r) => {
                if (r.resp_code == 0 && r.datas && r.datas.records.length) {
                    resolve(r.datas.records);
                } else {
                    resolve([]);
                }
            })
    })
}

/**
 * @description:获取所有的用户
 */
export const allUser = (params: AccountParams) => {
    var data = {
        keyStr: '',
        page: 1,
        rows: 100000,
    }
    return new Promise<void>((resolve, reject) => {
        defHttp.post<AccountListGetResultModel>({ url: Api.GetUserArr, data }).then((r) => {
            if (r.resp_code == 0 && r.datas && r.datas.records.length) {
                resolve(r.datas.records);
            } else {
                resolve([]);
            }
        })
    })
}

/**
 * @description:保存APP
 */
export const save = (params) => {
    return new Promise<void>((resolve, reject) => {
        defHttp.post<AccountListGetResultModel>({ url: Api.Save, params }).then((r) => {
            if (r.resp_code == 0 && r.datas) {
                resolve(r);
            } else {
                reject(r);
            }
        })
    })
}

/**
 * @description:删除应用
 */
export function deleteApp(params) {
    return defHttp.post({ url: Api.Delete, params })
}
