import { frogHttp, pigeonHttp } from '@/lib/http/instances'
import {
  AiUserInput,
  AiUserBaseOutput,
  AiUserStatOutput,
  AiUserGiftsInput,
  PageAiUserGiftListOutput,
  AiUserAlbumInput,
  PageAlbumListOutput,
  LikedStatus,
  PageMessageListOutput,
  PageParams,
  UserNoticeStatOutput,
  GetUserCreateCountResponse,
} from './types'

export const userService = {
  // 获取用户信息
  getAIUserBaseInfo: (data: AiUserInput): Promise<AiUserBaseOutput> => {
    return frogHttp.post('/web/ai-user-search/base-info', data, { ignoreError: true })
  },

  getSEOUserBaseInfo: (data: AiUserInput): Promise<{ nickname: string; homeImageUrl: string }> => {
    return frogHttp.post('/web/so/base-nfo', data, { ignoreError: true })
  },

  // 获取用户统计信息
  getAIUserStat: (data: AiUserInput): Promise<AiUserStatOutput> => {
    return frogHttp.post('/web/ai-user/stat', data)
  },

  // 获取用户礼物信息
  getAIUserGifts: (data: AiUserGiftsInput): Promise<PageAiUserGiftListOutput> => {
    return frogHttp.post('/web/ai-user-gift/list', data)
  },

  // 获取用户相册列表
  getAIUserAlbum: (data: AiUserAlbumInput): Promise<PageAlbumListOutput> => {
    return frogHttp.post('/web/ai-user/album-list', data)
  },

  // 点赞/取消点赞相册图片
  likeAlbumImage: (data: { albumId: number; likedStatus: LikedStatus }): Promise<void> => {
    return frogHttp.post('/web/album/like_or_cancel', data)
  },

  // 解锁付费相册内容
  unlockAlbumImage: (data: { aiId: number; imageId: number }): Promise<void> => {
    return frogHttp.post('/web/ai-user/album/unlock', data)
  },

  // 设置默认相册图片
  setDefaultAlbumImage: (data: { aiId: number; albumId: number }): Promise<void> => {
    return frogHttp.post('/web/ai-user/set-default-album', data)
  },

  // 设置相册图片解锁方式
  setAlbumImageUnlockMethod: (data: {
    aiId: number
    albumId: number
    unlockPrice: number
  }): Promise<void> => {
    return frogHttp.post('/web/ai-user/set-album-unlock-price', data)
  },

  // 删除相册图片
  deleteAlbumImage: (data: { albumId: number }): Promise<void> => {
    return frogHttp.post('/web/ai-user/album-del', data)
  },

  // 删除角色
  deleteCharacter: (data: { aiId: number }): Promise<void> => {
    return frogHttp.post('/web/ai-user/del', data)
  },

  // 添加相册图片
  addAlbumImage: (data: {
    aiId: number
    images: Array<{ url: string; width: number; height: number; unlockPrice: number }>
  }): Promise<void> => {
    return frogHttp.post('/web/ai-user/batch-add-album', data)
  },

  // 获取用户通知列表
  getUserNoticeList: (data: { page: PageParams }): Promise<PageMessageListOutput> => {
    return pigeonHttp.post('/web/message/list', data)
  },

  // 系统消息统计
  getUserNoticeStat: (): Promise<UserNoticeStatOutput> => {
    return pigeonHttp.post('/web/message/stat')
  },

  unlockImage: (data: {
    aiId: number
    albumId: number
    messageServerId?: string
  }): Promise<{ img1: string; img2: string; img3: string }> => {
    return frogHttp.post('/web/ai-user/unlock-album-img', data)
  },

  // 加密图片解锁后访问
  viewUnlockAlbumImage: (data: {
    aiId: number
    albumId: number
    messageServerId?: string
  }): Promise<{ img1: string; img2: string; img3: string } | null> => {
    return frogHttp.post('/web/ai-user/view-unlock-album-img', data, { ignoreError: true })
  },

  // 设置设备是否自动播放语音
  setAutoPlayVoice: (data: { aiId: number; isAutoPlayVoice: boolean }): Promise<void> => {
    return frogHttp.post('/web/chat-set/auto-play-voice', data)
  },

  // 获取用户相册创作次数
  getUserAlbumCreateCount: (): Promise<GetUserCreateCountResponse> => {
    return frogHttp.post('/web/user/get-user-create-count')
  },

  // 创建Ai形象-购买创作次数
  buyCreateImageCount: (data: { count: number }): Promise<void> => {
    return frogHttp.post('/web/ai/buy-create-image-count', data)
  },
}
