/**
 * 直播间 cacheLive 读接口（/app/cacheLive/*）
 * 写操作仍走 @/api/living.js
 */
import Request from '@/common/request.js'
import {
	liveRed,
	claim,
	coupon,
	liveDataLike,
	collectGoods,
	subNotifyLive,
	internetTraffic,
	liveInternetTraffic,
	loginByMp,
	getUserInfo,
	getIsAddKf,
	liveWatchUser,
	submitLiveQuiz,
	completionReceive,
	updateWatchDuration,
	receivePoints
} from '@/api/living.js'

let request = new Request().http

const api = {
	getlive: '/app/cacheLive/live',
	currentActivities: (liveId) => `/app/cacheLive/currentActivities?liveId=${liveId}`,
	getLiveViewData: (liveId) => `/app/cacheLive/liveData/getLiveViewData/${liveId}`,
	liveStore: (liveId, key) => `/app/cacheLive/liveGoods/liveStore/${liveId}?key=${key || ''}`,
	liveOrderUser: (liveId) => `/app/cacheLive/liveOrder/liveOrderUser/${liveId}`,
	liveMsg: (liveId, pageSize, pageNum) =>
		`/app/cacheLive/liveMsg/list/?liveId=${liveId}&pageSize=${pageSize}&pageNum=${pageNum}`,
	myLiveMsg: (liveId, pageSize, pageNum) =>
		`/app/cacheLive/liveMsg/myList?liveId=${liveId}&pageSize=${pageSize}&pageNum=${pageNum}`,
	liveLottery: '/app/cacheLive/liveLottery/detail',
	myLottery: '/app/cacheLive/liveLottery/myLottery',
	completionRecords: (liveId) => `/app/cacheLive/completion/records?liveId=${liveId}`,
	completionUnreceived: (liveId) => `/app/cacheLive/completion/unreceived?liveId=${liveId}`,
	remainingTime: (liveId) => `/app/cacheLive/completion/remaining-time?liveId=${liveId}`,
	integralLogs: (type) => {
		const q = type != null ? `?type=${type}` : ''
		return `/app/cacheLive/completion/integral-logs${q}`
	}
}

export function getlive(data) {
	return request(api.getlive, data, 'GET', 'application/json;charset=UTF-8')
}

export function currentActivities(liveId, data = {}) {
	return request(api.currentActivities(liveId), data, 'GET', 'application/json;charset=UTF-8')
}

export function getLiveViewData(liveId, data = {}) {
	return request(api.getLiveViewData(liveId), data, 'GET', 'application/json;charset=UTF-8')
}

export function liveStore(liveId, key, data) {
	return request(api.liveStore(liveId, key), data, 'GET', 'application/json;charset=UTF-8')
}

export function liveOrderUser(liveId, data = {}) {
	return request(api.liveOrderUser(liveId), data, 'GET', 'application/json;charset=UTF-8')
}

export function liveMsg(liveId, pageSize, pageNum, data = {}) {
	return request(api.liveMsg(liveId, pageSize, pageNum), data, 'GET', 'application/json;charset=UTF-8')
}

export function myLiveMsg(liveId, pageSize, pageNum, data = {}) {
	return request(api.myLiveMsg(liveId, pageSize, pageNum), data, 'GET', 'application/json;charset=UTF-8')
}

export function liveLottery(data) {
	return request(api.liveLottery, data, 'POST', 'application/json;charset=UTF-8')
}

export function myLottery(data) {
	return request(api.myLottery, data, 'GET', 'application/json;charset=UTF-8')
}
export function completionRecords(data) {
	const liveId = data?.liveId
	return request(api.completionRecords(liveId), data, 'GET', 'application/json;charset=UTF-8')
}

export function completionUnreceived(data) {
	const liveId = data?.liveId
	return request(api.completionUnreceived(liveId), data, 'GET', 'application/json;charset=UTF-8')
}

export function remainingTime(data) {
	const liveId = data?.liveId
	return request(api.remainingTime(liveId), data, 'GET', 'application/json;charset=UTF-8')
}

export function integrallogs(data) {
	return request(api.integralLogs(data?.type), data, 'GET', 'application/json;charset=UTF-8')
}

// 写接口：cacheLive 无对应实现，继续委托 living.js
export {
	liveRed,
	claim,
	coupon,
	liveDataLike,
	collectGoods,
	subNotifyLive,
	internetTraffic,
	liveInternetTraffic,
	loginByMp,
	getUserInfo,
	getIsAddKf,
	liveWatchUser,
	submitLiveQuiz,
	completionReceive,
	updateWatchDuration,
	receivePoints
}
