import request from "../request";
import { AxiosPromise } from "axios";
import { LocationQueryValue } from "vue-router";

interface loginRes {
	code: number;
	msg: string;
	data: {
		token: string;
		wxUserInfo: {
			nickname: string;
			headimgurl: string;
		};
	};
}

class Auth {
	/**微信code登陆 */
	login(code: string): AxiosPromise<loginRes> {
		
		return request({
			url: "/login/code",
			method: "post",
			headers: {
				isToken: false,
			},
			params: {
				authorizationCode: code,
			},
		});
	}
}

export const auth = new Auth();

/**
 *
 * @param code 微信code
 * @returns
 */
export async function login(code: LocationQueryValue | LocationQueryValue[]) {
	let res = await request({
		url: "/login/code",
		method: "post",
		headers: {
			isToken: false,
		},
		params: {
			authorizationCode: code,
		},
	});
	return <loginRes>res.data;
}

export async function userInfo() {
	return request({
		url: "/student/user/info",
	});
}
