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 metaAdminManageService{
    async getTreeSystem(payload:any,autotip=false){
        let result = await request({ url: `${metaRepo}/rest/admin/getAdminSystem`, 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/admin/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/admin/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/admin/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/admin/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/admin/searchDic`, method: "post", data: qs.stringify(payload),hashrequest },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

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

    async getMetaReadableByAdminPerssion(payload={},autotip=false,hashrequest=false){
        let result = await request({ url: `${metaRepo}/rest/admin/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/admin/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/admin/saveAttributeAuth`, method: "post", data:payload },autotip).then(data=>{
            return data;
        }).catch(error=>{
            return error
        })
        return result;
    }

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

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

export default new metaAdminManageService()
