/**
 * @description 用户成就相关API
 * @author yslg
 * @since 2025-10-15
 */

import { api } from '@/apis/index';
import type { UserAchievement, Achievement, ResultDomain } from '@/types';

/**
 * 用户成就API服务
 */
export const userAchievementApi = {
  /**
   * 获取用户成就列表
   * @param userID 用户ID
   * @returns Promise<ResultDomain<UserAchievement>>
   */
  async getUserAchievements(userID: string): Promise<ResultDomain<UserAchievement>> {
    const response = await api.get<UserAchievement>('/usercenter/achievement/user-list', { userID });
    return response.data;
  },

  /**
   * 获取所有成就列表
   * @returns Promise<ResultDomain<Achievement>>
   */
  async getAllAchievements(): Promise<ResultDomain<Achievement>> {
    const response = await api.get<Achievement>('/usercenter/achievement/list');
    return response.data;
  },

  /**
   * 检查用户成就进度
   * @param userID 用户ID
   * @param achievementID 成就ID
   * @returns Promise<ResultDomain<{ progress: number; isCompleted: boolean }>>
   */
  async checkAchievementProgress(userID: string, achievementID: string): Promise<ResultDomain<{ progress: number; isCompleted: boolean }>> {
    const response = await api.get<{ progress: number; isCompleted: boolean }>('/usercenter/achievement/progress', {
      userID,
      achievementID
    });
    return response.data;
  }
};
