import request from '@/utils/user_center_request';
import local_request from '@/utils/local_request';

	// myVPNGroup := router.Group("/vpn")
	// myVPNGroup.POST("/server_register", ServerRegisterHandler)
	// myVPNGroup.GET("/get_support_vpn_server", GetSupportVPNServerHandler)
	// myVPNGroup.POST("/update_client_status", UpdateClientStatusHandler)
	// myVPNGroup.POST("/update_server_status", UpdateServerStatusHandler)
	// myVPNGroup.GET("/get_client_config", GetClientConfigHandler) //prepare online
	// myVPNGroup.GET("/get_server_config", GetServerConfigHandler)
	// myVPNGroup.PUT("/client_heartbeat", ClientHeartbeatHandler)
	// myVPNGroup.GET("/get_vpn_user", GetVPNUserHandler)
	// myVPNGroup.POST("/set_vpn_server_config", SetVPNServerConfigHandler)
	// myVPNGroup.GET("/get_vpn_server_config", GetVPNServerConfigHandler)
	// myVPNGroup.GET("/get_server_online", GetVPNServerOnlineListHandler)
	// myVPNGroup.DELETE("/delete_vpn_server", DeleteVPNServerHandler)
	// myVPNGroup.POST("/set_vpn_ip_pool", SetVPNPoolHandler)
	// myVPNGroup.GET("/get_vpn_ip_pool", GetVPNAddressPoolHandler)
	// myVPNGroup.DELETE("/delete_vpn_ip_pool", DeleteVPNPoolHandler)
	// myVPNGroup.POST("/set_vpn_tunnel", SetVPNTunnelHandler)
	// myVPNGroup.DELETE("/delete_vpn_tunnel", DeleteVPNTunnelHandler)
	// myVPNGroup.GET("/get_vpn_tunnel_config", GetVPNTunnelConfigHandler)
export const GetSupportVPNServerHandler = () => {
    return request.get('/vpn/get_support_vpn_server')
}

export const GetVPNUserHandler = () => {
    return request.get('/vpn/get_vpn_user')
}

export const GetVPNAddressPoolHandler = () => {
    return request.get('/vpn/get_vpn_ip_pool')
}


export const SetVPNAddressPoolHandler = (Data) => {
    return request.post('/vpn/set_vpn_ip_pool', Data)
}

export const DeleteVPNAddressPoolHandler = (Data) => {
    return request.delete('/vpn/delete_vpn_ip_pool', { data: Data })
}

/**
 * 获取VPN隧道配置信息
 * @returns {Promise} 包含VPN隧道配置信息的Promise对象
 */
export const GetVPNTunnelConfigHandler = () => {

    return request.get('/vpn/get_vpn_tunnel_config')

}

export const SetVPNTunnelHandler = (Data) => {
    return request.post('/vpn/set_vpn_tunnel', Data)
}

export const GetVPNServerOnlineListHandler = () => {
    return request.get('/vpn/get_server_online')
}

export const GetSurppotVPNServerOnlineListHandler = () => {
    return request.get('/vpn/get_support_vpn_server')
}

export const DeleteVPNTunnelHandler = (Data) => {
    return request.delete('/vpn/delete_vpn_tunnel', { data: Data })
}

export const GetVPNServerConfigHandler = () => {
    return request.get('/vpn/get_vpn_server_config')
}


export const SetVPNServerConfigHandler = (Data) => {

    return request.post('/vpn/set_vpn_server_config', Data)

}

export const DeleteVPNServerHandler = (Data) => {
    return request.delete('/vpn/delete_vpn_server', { data: Data })
}

export const GetClientDownloadURLHandler = () => {
	return request.get("/vpn/clients_url")
}

export const GetServerOnlineUsers = (serverID:string) => {
	return request.get("/vpn/get_client_online_users?server_id=" + serverID)
}
export const KickOutOnlineUser = (Data) => {
	return request.post("/vpn/kick_out_user", Data)
}

export const LocalClientConnectHandler = (Data) => {
    return local_request.post('/vpn/connect', Data)
}
export const LocalClientDisConnectHandler = (Data) => {
	let url = '/vpn/disconnect?server_id=' + Data.server_id;
    return local_request.get(url)
}
//获取本地客户端连接状态
export const LocalClientStatusHandler = () => {
    return local_request.get('/vpn/get_status')
}

// VPN Policy Management APIs
// myVPNPolicyGroup := router.Group("/vpn_policy")
// myVPNPolicyGroup.GET("/get", GetMyVPNPolicyHandler)
// myVPNPolicyGroup.POST("/create", CreateMyVPNPolicyHandler)
// myVPNPolicyGroup.POST("/update", UpdateMyVPNPolicyHandler)
// myVPNPolicyGroup.DELETE("/delete", DeleteMyVPNPolicyHandler)

/**
 * 获取VPN策略列表
 * @param {Object} params 查询参数，包含server_id等
 * @returns {Promise} 包含VPN策略列表的Promise对象
 */
export const GetMyVPNPolicyHandler = (params) => {
    return request.get('/vpn_policy/get', { params })
}

/**
 * 创建VPN策略
 * @param {Object} data VPN策略数据
 * @returns {Promise} 创建结果的Promise对象
 */
export const CreateMyVPNPolicyHandler = (data) => {
    return request.post('/vpn_policy/create', data)
}

/**
 * 更新VPN策略
 * @param {Object} data VPN策略更新数据，包含id
 * @returns {Promise} 更新结果的Promise对象
 */
export const UpdateMyVPNPolicyHandler = (data) => {
    return request.post('/vpn_policy/update', data)
}

/**
 * 删除VPN策略
 * @param {Object} data 删除参数，包含id和server_id
 * @returns {Promise} 删除结果的Promise对象
 */
export const DeleteMyVPNPolicyHandler = (data) => {
	let url =  '/vpn_policy/delete';

	if (data.id){
		url += "?id="+data.id
	}
	if (data.server_id){
		url += "&server_id=" + data.server_id
	}
    return request.delete(url)
}

export const MatchVPNPolicyHandler = (data) => {
	return request.post('/vpn_policy/match', data)
}