import { BASE_URL } from '@/config/api.config'

interface RequestConfig {
	method?: 'GET' | 'POST' | 'PUT' | 'DELETE'
	data?: any
}

export const request = async (
	url: string,
	config: RequestConfig
) => {
	return new Promise<any>((resolve, reject) => {
		uni.request({
			url: BASE_URL + url,
			method: config.method ?? 'GET',
			data: config.data || null,
			
			success: (res) => {
				resolve(res.data)
			},
			fail: (err) => {
				reject(err)
			}
		})
	})
}