import { AddReq, UserPageQuery } from '@fast-crud/fast-crud';
import { request } from '/@/utils/service';

export const apiPrefix = '/api/system/app_user/';
export function GetList(query: UserPageQuery) {
	return request({
		url: apiPrefix,
		method: 'get',
		params: query,
	});
}
export function GetObj(id: InfoReq) {
	return request({
		url: apiPrefix + id+ '/',
		method: 'get',
	});
}

export function AddObj(obj: AddReq) {
	return request({
		url: apiPrefix,
		method: 'post',
		data: obj,
	});
}

export function UpdateObj(obj: EditReq) {
	return request({
		url: apiPrefix + obj.id + '/',
		method: 'put',
		data: obj,
	});
}

export function DelObj(id: DelReq) {
	return request({
		url: apiPrefix + id + '/',
		method: 'delete',
		data: { id },
	});
}
export function GetPermission() {
    return request({
        url: apiPrefix,
        method: 'get',
    });
}

// 批量导出用户
export function BatchExportUsers(userIds: number[], userType?: number) {
    const params: any = {
        user_ids: userIds
    };
    
    // 如果指定了用户类型，添加到查询参数中
    if (userType !== undefined) {
        params.user_type = userType;
    }
    
    return request({
        url: apiPrefix + 'export_selected/',
        method: 'post',
        data: params,
        responseType: 'blob', // 重要：设置响应类型为blob以处理文件下载
    });
}


export function GetTree() {
	return request({
		url: `/api/system/organization/tree/`,
		method: 'get',
	});
}