import request from '@/common/system/request';


/**
 *  匿名登录
 * @returns {Promise<any>}
 */
export const getAnonymousLogin = async (code) => {
    const res = await request.post("user/UseAnonymousLogin", { code: code });
    if (res.code == 0) {
        return res.data;
    }
    return null;
}

/**
 * 微信小程序授权拉取手机号码并登录
 * @param {*} code 
 * @param {*} sessionAuthId 
 * @returns 
 */
export const ueWxPhoneNumberLogin = async (code, sessionAuthId) => {
    const res = await request.post("user/UseWxPhoneNumberLogin", { code: code, sessionAuthId: sessionAuthId });
    if (res.code == 0) {
        return res.data;
    }
    return null;
}

/**
 * 匿名登录
 * @returns 
 */
export const anonymousLogin = async () => {
    const res = await request.post("user/AnonymousLogin");
    if (res.code == 0) {
        return res.data;
    }
    return null;
}

/**
 * 微信小程序匿名授权登录，手机号已授权过
 * @param {*} code 
 * @param {*} sessionAuthId 
 * @returns 
 */
export const useWxAnonymousLogin = async (sessionAuthId) => {
    const res = await request.post("user/UseWxAnonymousLogin", { sessionAuthId: sessionAuthId });
    if (res.code == 0) {
        return res.data;
    }
    return null;
}

/**
 * 获取用户信息
 * @returns 
 */
export const getUserInfo = async () => {
    const res = await request.post("user/GetUserInfo");
    if (res.code == 0) {
        return res.data;
    }
    return null;
}

/**
 * 修改用户信息
 * @param {*} nickName 
 * @param {*} avatar 
 * @param {*} sex 
 * @param {*} birthday 
 * @returns 
 */
export const editUserInfo = async (nickName, avatar, sex, birthday) => {

    const res = await request.post("user/EditUserInfo", {
        nickName,
        avatar,
        sex,
        birthday
    });
    if (res.code == 0) {
        return true;
    }
    return false;
}

/**
 * 获取黑名单列表
 * @returns {Promise<any>}
 */
export const getMyBlackList = async () => {
    const res = await request.get("user/GetMyBlackList");
    if (res.code == 0) {
        return res.data;
    }
    return null;
}

/**
 * 添加黑名单
 * @param {*} userId 要拉黑的用户ID
 * @returns {Promise<boolean>}
 */
export const addUserBlack = async (userId) => {
    const res = await request.post("user/AddUserBlack", { id: userId });
    if (res.code == 0) {
        return true;
    }
    return false;
}

/**
 * 取消拉黑名单
 * @param {*} userId 要取消拉黑的用户ID
 * @returns {Promise<boolean>}
 */
export const cancelUserBlack = async (userId) => {
    const res = await request.post("user/CancelUserBlack", { id: userId });
    if (res.code == 0) {
        return true;
    }
    return false;
}
/**
 * 添加黑名单
 * @param {*} userId 要拉黑的用户ID
 * @returns {Promise<boolean>}
 */
export const usePay = async (money) => {
    const res = await request.post("user/UsePay", { money: money });
    if (res.code == 0) {
        return res.data;
    }
    return null;
}
export const userInterface = {
 
    getAnonymousLogin,
    ueWxPhoneNumberLogin,
    anonymousLogin,
    useWxAnonymousLogin,
    getUserInfo,
    editUserInfo,
    getMyBlackList,
    addUserBlack,
    cancelUserBlack,
    usePay
}


