import { BaseResource , BaseResourceOptions } from '@gitbeaker/requester-utils' ; import { UserSchema } from '../resources/Users' ; import { BaseRequestOptions , endpoint , PaginatedRequestOptions , RequestHelper , Sudo , } from '../infrastructure' ; export interface DiscussionNotePosition { base_sha : string ; start_sha : string ; head_sha : string ; old_path : string ; new_path : string ; position_type : string ; old_line : number ; new_line : number ; } export interface DiscussionNote { id : number ; type ? : string ; body : string ; attachment ? : string ; author : Omit < UserSchema , 'created_at' > ; created_at : string ; updated_at : string ; system : boolean ; noteable_id : number ; noteable_type : string ; noteable_iid ? : number ; resolvable : boolean ; position ? : DiscussionNotePosition ; } export interface DiscussionSchema extends Record < string , unknown > { id : string ; individual_note : boolean ; notes ? : DiscussionNote [ ] ; } export class ResourceDiscussions < C extends boolean = false > extends BaseResource < C > { protected resource2Type : string ; constructor ( resourceType , resource2Type , options ) { super ( { prefixUrl : resourceType , ... options } ) ; this . resource2Type = resource2Type ; } addNote ( resourceId , resource2Id , discussionId , noteId , body , options ? ) { return RequestHelper . post ( ) ( this , endpoint `${ resourceId }/${ this . resource2Type }/${ resource2Id }/discussions/${ discussionId }/notes` , { query : { body } , noteId , ... options } ) ; } all ( resourceId , resource2Id , options ? ) { return RequestHelper . get < DiscussionSchema [ ] > ( ) ( this , endpoint `${ resourceId }/${ this . resource2Type }/${ resource2Id }/discussions` , options ) ; } create ( resourceId , resource2Id , body , options ? ) { return RequestHelper . post < DiscussionSchema > ( ) ( this , endpoint `${ resourceId }/${ this . resource2Type }/${ resource2Id }/discussions` , { query : { body } , ... options , } ) ; } editNote ( resourceId , resource2Id , discussionId , noteId , { body , ... options } = { } ) { return RequestHelper . put < DiscussionSchema > ( ) ( this , endpoint `${ resourceId }/${ this . resource2Type }/${ resource2Id }/discussions/${ discussionId }/notes/${ noteId }` , { query : { body } , ... options , } ) ; } removeNote ( resourceId , resource2Id , discussionId , noteId , options ? ) { return RequestHelper . del ( ) ( this , endpoint `${ resourceId }/${ this . resource2Type }/${ resource2Id }/discussions/${ discussionId }/notes/${ noteId }` , options ) ; } show ( resourceId , resource2Id , discussionId , options ? ) { return RequestHelper . get < DiscussionSchema > ( ) ( this , endpoint `${ resourceId }/${ this . resource2Type }/${ resource2Id }/discussions/${ discussionId }` , options ) ; } }