import { Api } from '../api' export const COMMENTS_API = '/service/element-comments' export interface CommentPostData { text: string organization: string private: boolean parent_id?: string } export interface Comment { _id: string author: { id: string name: string } created_at: string parent_id: string private: boolean text: string replies?: Comment[] } export interface BatchCommentRequest { keys: string[] // example: ['elementHash1+extraPath1', 'elementHash2+extraPath2'] // Future metadata fields can be added here } interface BatchCommentResult { comments?: Comment[] error?: string } export type BatchCommentResponse = Record export class Comments { api: Api constructor(api: Api) { this.api = api } async getComments(elementHash: string, extraPath?: string) { return this.api.apisauce.get( `${COMMENTS_API}/comments/${elementHash}`, { extraPath, }, { cache: false, }, ) } getCommentsBatch(data: BatchCommentRequest) { return this.api.apisauce.post( `${COMMENTS_API}/comments/batch`, data, ) } async postComment( elementHash: string, data: CommentPostData, extraPath?: string, ) { return this.api.apisauce.post( `${COMMENTS_API}/comments/${elementHash}`, data, { params: { extraPath, }, }, ) } async archiveComment( elementHash: string, commentId: string, extraPath?: string, ) { void elementHash return this.api.apisauce.delete( `${COMMENTS_API}/comments/element/${commentId}`, { params: { extraPath, }, }, ) } }