import { reactive } from "vue";

type IUser = {
	username?: string;
	nickname?: string;
	/** 真实姓名 */
	realName?: string;
	/** 会员结束时间 */
	membershipEndTime?: string;
	tenantId?: number;
	/** 声部名称 */
	subjectNames?: string;
	subjectName?: string;
	/** 头像 */
	avatar?: string;
	memberRankSettingId?: number;
	id?: string | number;
	clientType?: "BACKEND" | "SCHOOL" | "TEACHER" | "STUDENT";
};
type IStatus = "init" | "login" | "logout" | "error";
type IPlatformType = "STUDENT" | "TEACHER" | "WEB" | "";
type IPlatformApi = "/api-student" | "/api-teacher" | "/api-web" | "/api-backend" | "/edu-app";
type IProxy = "" | "/gym" | "/colexiu" | "/orchestra" | "/instrument";

export interface IStoreData {
	platformType: IPlatformType;
	platformApi: IPlatformApi;
	proxy: IProxy;
	isApp: boolean;
}

export const storeData = reactive({
	status: "init" as IStatus,
	/** 用户信息 */
	user: {} as IUser,
	/** 端口 */
	platformType: "TEACHER" as IPlatformType,
	/** api地址前缀 */
	platformApi: "/edu-app" as IPlatformApi,
	/** 开发模式api前缀 */
	proxy: "" as IProxy,
	/** 是否在APP中 */
	isApp: false,
});

/** 初始化 */
export const setStoreData = (data: IStoreData) => {
	Object.assign(storeData, data);
};

/** 设置用户信息 */
export const setUserInfo = (user: IUser) => {
	storeData.status = "login";
	storeData.user = user || {};
};
export const setLogout = () => {
	storeData.status = "logout";
	storeData.user = {};
};
export const setLoginError = () => {
	storeData.status = "error";
	storeData.user = {};
};
