import { DataModel, transformArrayDataModel } from '@imengyu/js-request-transform';
import { AppServerRequestModule } from '../RequestModules';
import { GetContentDetailItem } from '../CommonContent';

export class UserApi extends AppServerRequestModule<DataModel> {

  constructor() {
    super();
  }

  async like(id: number) {
    return (this.post('/content/main_body_user/like', '点赞', { content_id: id }));
  }
  async unlike(id: number) {
    return (this.post('/content/main_body_user/unLike', '取消点赞', { content_ids: id }));
  }
  async collect(id: number) {
    return (this.post('/content/main_body_user/collect', '收藏', { content_id: id }));
  }
  async uncollect(id: number) {
    return (this.post('/content/main_body_user/unCollect', '取消收藏', { content_ids: id }));   
  }
  async getUserCollect(page: number, pageSize: number) {
    const res = await (this.post<{
      data: GetContentDetailItem[],
      total: number,
    }>('/content/main_body_user/getUserCollect', '获取用户收藏', { page, pageSize })) 
    return { 
      list: transformArrayDataModel(GetContentDetailItem, res.data?.data ?? [], `获取用户收藏列表`, true),
      total: res.data?.total as number ?? 0,
    };
  }
}

export default new UserApi();
