import request from "@/utils/request"
import qs from "qs"
import config from "@/commons"

const {api:{metaRepo,sessionInfo}} =config

declare global {
    interface Navigator {
        msSaveBlob?: (blob: any, defaultName?: string) => boolean
    }
}

class metaUserManageService{
    async getTreeSystem(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/user/getUserSystem`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getChildrenBySystem(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/user/getChildBySystem`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getChildrenByParentId(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/user/getChildByParentId`, method: "get", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getSystemChildrenByPage(payload:any,autotip=false,hashrequest=false){
        let result = await request({ url: `${metaRepo}/rest/user/getPageChildBySys`, method: "post",params:payload.params, data:payload.data,hashrequest },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getChildByIdAndSysByPage(payload:any,autotip=false,hashrequest=false){
        let result = await request({ url: `${metaRepo}/rest/user/getPageChild`, method: "post",params:payload.params,data:payload.data,hashrequest },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaDiscByPermission(payload={},autotip=false,hashrequest=false){
        let result = await request({ url: `${metaRepo}/rest/user/searchDic`, method: "post", data: qs.stringify(payload),hashrequest },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaSearhList(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/user/findPage`, method: "post", data:qs.stringify(payload.params) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaByUserPerssion(payload={},autotip=false,hashrequest=false){
        let result = await request({ url: `${metaRepo}/rest/user/getById`, method: "get", data: payload,hashrequest },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getMetaReadableByUserPerssion(payload={},autotip=false,hashrequest=false){
        let result = await request({ url: `${metaRepo}/rest/user/readable/:id`, method: "get", data: payload,urldata:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getModelColumnByAuth(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/user/getAttributeAuth`, method: "post", data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async saveModelColumnByAuth(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/user/saveAttributeAuth`, method: "post", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

    async getModelAllowSortList(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/user/findSortColumnByModel`, method: "post",data:qs.stringify(payload) },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }
}

export default new metaUserManageService()
