import request, { Response } from '~/api/request';

export interface DynamicListParams {
  pageNo: number;
  pageSize: number;
  userId: number;
}

export interface Dynamic {
  userId: number;
  id: number;
  title: string;
  description: string;
  location: string;
  lat: number;
  lon: number;
  mediaVO: {
    type: number;
    url: string;
  }[];
  likesCount: number;
  commentCount: number;
  likes: boolean;
  userBaseInfo: {
    id: number;
    nickName: string;
    userImg: string;
  };
}

export interface DynamicListResp {
  pageNo: 1;
  pageSize: 10;
  list: Array<Dynamic>;
  totalCount: 0;
  totalPage: 0;
}

export interface CommentParams {
  content: string; // 评论内容
  dynamicId: number; // 动态id
  parentId?: number; // 父级评论
  rootPath: string;
}

export interface ByDynamicResp {
  id: number;
  description: string;
  likesCount: number;
  dynamicPublishTime: string;
  children: ByDynamicResp[];
  userBaseInfo: {
    id: number;
    nickName: string;
    userImg: string;
  };
  mediaVO: { type: number; url: string };
}
export interface dynamicDetail extends ByDynamicResp {
  commentAndReplyVO: ByDynamicResp[];
}

export default {
  /**
   * 论坛动态列表
   * @param params
   * @returns
   */
  dynamicList(params: DynamicListParams): Promise<Response<DynamicListResp>> {
    return request('/release/dynamic/dynamicList', 'get', params);
  },

  // 评论
  comment(params: CommentParams): Promise<Response<null>> {
    return request('/release/dynamic/comment', 'post', params);
  },

  // 动态详情
  byDynamic(params: { dynamicId: number }): Promise<Response<dynamicDetail>> {
    return request('/release/dynamic/dynamicDetails', 'get', params);
  },

  // 点赞或取消点赞
  likeOrCancel(params: { dynamicId: number }) {
    return request('/release/dynamic/likeOrCancel', 'get', params);
  },
};
