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

/**
 * 获取预约记录
 * @param {number} index 
 * @param {number} size 
 * @returns 
 */
export const getReservationList = async (index = 1, size = 20) => {
    console.log('getReservationList', index, size);

    const res = await request.getOrCache("sq/GetReservationList", { pageIndex: index, pageSize: size }, 5);
    if (res.code == 0) {
        return res.data;
    }
    return null;
}

/**
 * 获取我的预约记录
 * @param {number} type 0 参与者，1发起者
 * @param {number} index 起始页
 * @param {number} size 页大小
 * @returns {Promise<any>}
 */
export const getMyReservation = async (type = 0, index = 1, size = 10) => {
    const res = await request.get("sq/GetMyReservation", {
        type: type,
        index: index,
        size: size
    });
    if (res.code == 0) {
        return res.data;
    }
    return null;
}

/**
 * 获取正在进行的预约
 * @returns {Promise<any>}
 */
export const getMyUseReservation = async () => {
    const res = await request.get("sq/GetMyUseReservation");
    if (res.code == 0) {
        return res.data;
    }
    return null;
}

/**
 * 获取预约评价
 * @param {number} reId 预约ID
 * @returns {Promise<any>}
 */
export const getEvaluateServices = async (reId) => {
    const res = await request.get("sq/GetEvaluateServices", { reId: reId });
    if (res.code == 0) {
        return res.data;
    }
    return null;
}

/**
 * 添加预约评价
 * @param {Object} evaluate 评价数据
 * @param {number} evaluate.reservation_id 预约ID
 * @param {number} evaluate.to_user_id 被评价用户ID
 * @param {number} evaluate.play_level 游戏水平评分
 * @param {number} evaluate.skills_level 技能水平评分
 * @returns {Promise<any>}
 */
export const addEvaluateServices = async (evaluate) => {
    const res = await request.post("sq/AddEvaluateServices", evaluate);
    if (res.code == 0) {
        return true;
    }
    return false;
}

/**
 * 获取我的声誉记录
 * @param {number} pageIndex 起始页
 * @param {number} pageSize 页大小
 * @returns {Promise<any>} [{title:"标题",reputation_value:"变化值","created_at":"变化时间"}]
 */
export const getReputationByUser = async (pageIndex = 1, pageSize = 20) => {
    const res = await request.get("sq/GetReputationByUser", {
        pageIndex: pageIndex,
        pageSize: pageSize
    });
    if (res.code == 0) {
        //data:
        return res.data;
    }
    return null;
}

/**
 * 获取可预约的房间列表
 * @param {number} startTime 开始时间 时间戳(秒)
 * @param {number} endTime 结束时间 时间戳(秒)
 * @returns {Promise<any>} [{id:"房间id",name:"房间名称"}]
 */
export const getReservationRoomList = async (startTime, endTime) => {
    const res = await request.get("sq/GetReservationRoomList", {
        startTime: startTime,
        endTime: endTime
    });
    if (res.code == 0) {
        return res.data;
    }
    return null;
}

 


export const sqInterface = {
    getReservationList,
    getMyReservation,
    getMyUseReservation,
    getEvaluateServices,
    addEvaluateServices,
    getReputationByUser,
    getReservationRoomList
}