/**
 * @description 用户浏览记录相关API
 * @author yslg
 * @since 2025-10-15
 */

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

/**
 * 用户浏览记录API服务
 */
export const userBrowseRecordApi = {
  /**
   * 获取用户浏览记录
   * @param userID 用户ID
   * @param browseType 浏览类型
   * @returns Promise<ResultDomain<UserBrowseRecord>>
   */
  async getUserBrowseRecords(userID: string, browseType?: number): Promise<ResultDomain<UserBrowseRecord>> {
    const response = await api.get<UserBrowseRecord>('/usercenter/browse-record/list', {
      userID,
      browseType
    });
    return response.data;
  },

  /**
   * 添加浏览记录
   * @param record 浏览记录数据
   * @returns Promise<ResultDomain<UserBrowseRecord>>
   */
  async addBrowseRecord(record: UserBrowseRecord): Promise<ResultDomain<UserBrowseRecord>> {
    const response = await api.post<UserBrowseRecord>('/usercenter/browse-record/add', record);
    return response.data;
  },

  /**
   * 清空浏览记录
   * @param userID 用户ID
   * @returns Promise<ResultDomain<boolean>>
   */
  async clearBrowseRecords(userID: string): Promise<ResultDomain<boolean>> {
    const response = await api.post<boolean>('/usercenter/browse-record/clear', { userID });
    return response.data;
  }
};
