/**
 * 领养专区相关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 getAdoptionPets = (params = {}, config = {}) => {
	return BaseRequest.get('/adoption/pets', params, 'SILENT_REQUEST', config)
}

/**
 * 搜索宠物
 * @param {Object} searchParams 搜索参数
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const searchPets = (searchParams, config = {}) => {
	return BaseRequest.get('/adoption/pets/search', searchParams, 'SILENT_REQUEST', config)
}

/**
 * 筛选宠物
 * @param {Object} filterParams 筛选参数
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const filterPets = (filterParams, config = {}) => {
	return BaseRequest.post('/adoption/pets/filter', filterParams, 'PUBLIC_REQUEST', null, config)
}

/**
 * 获取宠物详情
 * @param {String|Number} petId 宠物ID
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const getAdoptionPetDetail = (petId, config = {}) => {
	return BaseRequest.get(`/adoption/pets/${petId}`, {}, 'PUBLIC_REQUEST', config)
}

/**
 * 申请领养
 * @param {Object} adoptionData 领养申请数据
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const applyAdoption = (adoptionData, config = {}) => {
	return BaseRequest.post('/adoption/apply', adoptionData, 'AUTHENTICATED_UPDATE', LOADING_TEXTS.SUBMIT_APPLICATION, config)
}

/**
 * 获取我的领养申请
 * @param {Object} params 查询参数
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const getMyAdoptionApplications = (params = {}, config = {}) => {
	return BaseRequest.get('/adoption/my-applications', params, 'AUTHENTICATED_QUERY_WITH_LOADING', config)
}

/**
 * 取消领养申请
 * @param {String|Number} applicationId 申请ID
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const cancelAdoptionApplication = (applicationId, config = {}) => {
	return BaseRequest.delete(`/adoption/applications/${applicationId}`, {}, 'AUTHENTICATED_DELETE', LOADING_TEXTS.CANCEL_APPLICATION, config)
}

/**
 * 获取领养机构列表
 * @param {Object} params 查询参数
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const getAdoptionOrganizations = (params = {}, config = {}) => {
	return BaseRequest.get('/adoption/organizations', params, 'PUBLIC_REQUEST', config)
}

/**
 * 获取领养机构详情
 * @param {String|Number} orgId 机构ID
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const getOrganizationDetail = (orgId, config = {}) => {
	return BaseRequest.get(`/adoption/organizations/${orgId}`, {}, 'PUBLIC_REQUEST', config)
}

/**
 * 收藏宠物
 * @param {String|Number} petId 宠物ID
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const favoritePet = (petId, config = {}) => {
	return BaseRequest.post(`/adoption/pets/${petId}/favorite`, {}, 'AUTHENTICATED_UPDATE', null, config)
}

/**
 * 取消收藏宠物
 * @param {String|Number} petId 宠物ID
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const unfavoritePet = (petId, config = {}) => {
	return BaseRequest.delete(`/adoption/pets/${petId}/favorite`, {}, 'AUTHENTICATED_DELETE', null, config)
}

/**
 * 获取收藏的宠物列表
 * @param {Object} params 查询参数
 * @param {Object} config 自定义配置
 * @returns {Promise}
 */
export const getFavoritePets = (params = {}, config = {}) => {
	return BaseRequest.get('/adoption/favorites', params, 'AUTHENTICATED_QUERY_WITH_LOADING', config)
}
