/**
 * 商品模块 - 商品列表、详情、奖品相关接口
 */
import RequestManager from '../request';

/**
 * 获取商品列表
 * @param {Object} params 查询参数
 * @param {Number} params.page 页码
 * @param {Number} params.type 商品类型
 * @param {Number} params.pageSize 每页数量
 * @returns {Promise} 商品列表
 */
export const getGoodsList = async (params = {}) => {
    return await RequestManager.get('/goods_list', params, true);
};

/**
 * 获取商品详情
 * @param {Number} goodsId 商品ID
 * @param {Number} goodsNum 箱号（可选）
 * @returns {Promise} 商品详情
 */
export const getGoodsDetail = async (goodsId, goodsNum = null) => {
    const params = {
        goods_id: goodsId
    };
    if (goodsNum !== null) {
        params.goods_num = goodsNum;
    }
    return await RequestManager.get('/goods_detail', params, true);
};

/**
 * 获取子奖品列表
 * @param {Number} goodsId 商品ID
 * @param {Number} goodsNum 箱号（可选）
 * @param {Number} goodsListId 商品列表ID（可选）
 * @returns {Promise} 子奖品列表
 */
export const getGoodsChildren = async (goodsId, goodsNum = null, goodsListId = null) => {
    const params = { goods_id: goodsId };
    if (goodsNum !== null) {
        params.goods_num = goodsNum;
    }
    if (goodsListId !== null) {
        params.goods_list_id = goodsListId;
    }
    return await RequestManager.post('/goods_children', params);
};

/**
 * 获取商品扩展配置
 * @param {Number} goodsId 商品ID
 * @returns {Promise} 扩展配置
 */
export const getGoodsExtend = async (goodsId) => {
    return await RequestManager.get('/goods_extend', {
        goods_id: goodsId
    });
};

/**
 * 获取箱号列表
 * @param {Number} goodsId 商品ID
 * @returns {Promise} 箱号列表
 */
export const getGoodsNumList = async (goodsId) => {
    return await RequestManager.get('/goods_num_list', {
        goods_id: goodsId
    });
};

/**
 * 获取箱号详情
 * @param {Number} goodsId 商品ID
 * @param {Number} goodsNum 箱号
 * @returns {Promise} 箱号详情
 */
export const getGoodsNumDetail = async (goodsId, goodsNum) => {
    return await RequestManager.get('/goods_num_detail', {
        goods_id: goodsId,
        goods_num: goodsNum
    });
};

/**
 * 获取奖品数量统计
 * @param {Number} goodsId 商品ID
 * @returns {Promise} 奖品数量统计
 */
export const getGoodsPrizeCount = async (goodsId) => {
    return await RequestManager.get('/goodslist_count', {
        goods_id: goodsId
    });
};

/**
 * 获取奖品内容
 * @param {Number} goodsId 商品ID
 * @param {Number} pageNo 页码/箱号范围
 * @param {Number} sort 排序方式 1-箱号 2-余量
 * @returns {Promise} 奖品内容
 */
export const getGoodsPrizeContent = async (goodsId, pageNo = 0, sort = 1) => {
    return await RequestManager.get('/goodslist_content', {
        goods_id: goodsId,
        page_no: pageNo,
        sort: sort
    });
};

/**
 * 获取中奖记录
 * @param {Object} params 查询参数
 * @param {Number} params.goods_id 商品ID
 * @param {Number} params.page 页码
 * @param {Number} params.pageSize 每页数量
 * @returns {Promise} 中奖记录
 */
export const getGoodsPrizeLogs = async (params = {}) => {
    return await RequestManager.get('/goods_prize_logs', params, true);
};

/**
 * 获取预售日历
 * @param {Object} params 查询参数
 * @returns {Promise} 预售日历数据
 */
export const getPreSaleCalendar = async (params = {}) => {
    return await RequestManager.get('/yushourili', params, true);
};

/**
 * 获取领主王数据
 * @param {Object} params 查询参数
 * @param {Number} params.goods_id 商品ID
 * @param {Number} params.page 页码
 * @returns {Promise} 领主王数据
 */
export const getBossData = async (params = {}) => {
    return await RequestManager.get('/ling_zhu_king', params);
};

/**
 * 获取无限赏商品详情
 * @param {Number} goodsId 商品ID
 * @returns {Promise} 商品详情
 */
export const getInfiniteGoodsDetail = async (goodsId) => {
    return await RequestManager.get('/infinite_goodsdetail', {
        goods_id: goodsId
    }, true);
};

/**
 * 获取一番赏商品详情（通过POST）
 * @param {Number} goodsId 商品ID
 * @param {Number} goodsNum 箱号（可选）
 * @returns {Promise} 商品详情
 */
export const getGoodsDetailPost = async (goodsId, goodsNum = null) => {
    const params = { goods_id: goodsId };
    if (goodsNum !== null) {
        params.goods_num = goodsNum;
    }
    return await RequestManager.post('/goodsdetail', params);
};

/**
 * 获取连击赏商品详情
 * @param {Number} goodsId 商品ID
 * @param {Number} type 类型 0-连击赏 1-秘宝池
 * @returns {Promise} 商品详情
 */
export const getLianJiGoodsDetail = async (goodsId, type = 0) => {
    return await RequestManager.post('/infinite_goodsdetail2', {
        goods_id: goodsId,
        type: type
    });
};

/**
 * 获取一番赏中奖记录
 * @param {Object} params 查询参数
 * @param {Number} params.goods_id 商品ID
 * @param {Number} params.goods_num 箱号
 * @param {Number} params.shang_id 赏品ID
 * @param {Number} params.page 页码
 * @returns {Promise} 中奖记录
 */
export const getShangLog = async (params = {}) => {
    return await RequestManager.post('/shang_log', params);
};

/**
 * 获取无限赏/连击赏中奖记录
 * @param {Object} params 查询参数
 * @param {Number} params.goods_id 商品ID
 * @param {Number} params.shang_id 赏品ID
 * @param {Number} params.is_mibao 是否秘宝池
 * @param {Number} params.page 页码
 * @returns {Promise} 中奖记录
 */
export const getInfiniteShangLog = async (params = {}) => {
    return await RequestManager.post('/infinite_shang_log', params);
};