/**
 * 评价相关API接口模块
 */

import BaseRequest from '../utils/request-helper.js'
import { LOADING_TEXTS } from '../config/constants.js'

/**
 * 获取评价列表
 * @param {Object} params 查询参数
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const getReviews = (params = {}, config = {}) => {
	return BaseRequest.get('/reviews', params, 'SILENT_REQUEST', config)
}

/**
 * 获取特定对象的评价列表
 * @param {String} targetType 目标类型 (pet, organization, service)
 * @param {String|Number} targetId 目标ID
 * @param {Object} params 查询参数
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const getTargetReviews = (targetType, targetId, params = {}, config = {}) => {
	return BaseRequest.get(`/reviews/${targetType}/${targetId}`, params, 'SILENT_REQUEST', config)
}

/**
 * 添加评价
 * @param {Object} reviewData 评价数据
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const addReview = (reviewData, config = {}) => {
	return BaseRequest.post('/reviews', reviewData, 'AUTHENTICATED_UPDATE', LOADING_TEXTS.SUBMIT_REVIEW, config)
}

/**
 * 更新评价
 * @param {String|Number} reviewId 评价ID
 * @param {Object} reviewData 评价数据
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const updateReview = (reviewId, reviewData, config = {}) => {
	return BaseRequest.put(`/reviews/${reviewId}`, reviewData, 'AUTHENTICATED_UPDATE', LOADING_TEXTS.UPDATE_REVIEW, config)
}

/**
 * 删除评价
 * @param {String|Number} reviewId 评价ID
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const deleteReview = (reviewId, config = {}) => {
	return BaseRequest.delete(`/reviews/${reviewId}`, {}, 'AUTHENTICATED_DELETE', LOADING_TEXTS.DELETE_REVIEW, config)
}

/**
 * 获取我的评价列表
 * @param {Object} params 查询参数
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const getMyReviews = (params = {}, config = {}) => {
	return BaseRequest.get('/reviews/my', params, 'AUTHENTICATED_QUERY_WITH_LOADING', config)
}

/**
 * 点赞评价
 * @param {String|Number} reviewId 评价ID
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const likeReview = (reviewId, config = {}) => {
	return BaseRequest.post(`/reviews/${reviewId}/like`, {}, 'AUTHENTICATED_QUERY', null, config)
}

/**
 * 取消点赞评价
 * @param {String|Number} reviewId 评价ID
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const unlikeReview = (reviewId, config = {}) => {
	return BaseRequest.delete(`/reviews/${reviewId}/like`, {}, 'AUTHENTICATED_QUERY', null, config)
}

/**
 * 举报评价
 * @param {String|Number} reviewId 评价ID
 * @param {Object} reportData 举报数据
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const reportReview = (reviewId, reportData, config = {}) => {
	return BaseRequest.post(`/reviews/${reviewId}/report`, reportData, 'AUTHENTICATED_UPDATE', LOADING_TEXTS.SUBMIT_REPORT, config)
}

/**
 * 回复评价
 * @param {String|Number} reviewId 评价ID
 * @param {Object} replyData 回复数据
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const replyReview = (reviewId, replyData, config = {}) => {
	return BaseRequest.post(`/reviews/${reviewId}/reply`, replyData, 'AUTHENTICATED_UPDATE', LOADING_TEXTS.REPLY_REVIEW, config)
}

/**
 * 获取评价统计
 * @param {String} targetType 目标类型
 * @param {String|Number} targetId 目标ID
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const getReviewStats = (targetType, targetId, config = {}) => {
	return BaseRequest.get(`/reviews/${targetType}/${targetId}/stats`, {}, 'PUBLIC_REQUEST', config)
}
