package com.betriebsratkanzlei.legalconsenthub.comment

import com.betriebsratkanzlei.legalconsenthub_api.api.CommentApi
import com.betriebsratkanzlei.legalconsenthub_api.model.CommentDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateCommentDto
import com.betriebsratkanzlei.legalconsenthub_api.model.PagedCommentDto
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RestController
import java.util.UUID

@RestController
class CommentController(
    val commentService: CommentService, val commentMapper: CommentMapper, val pagedCommentMapper: PagedCommentMapper
) : CommentApi {
    override fun createComment(
        applicationFormId: UUID,
        formElementId: UUID,
        createCommentDto: CreateCommentDto
    ): ResponseEntity<CommentDto> {
        return ResponseEntity.ok(
            commentMapper.toCommentDto(
                commentService.createComment(applicationFormId, formElementId, createCommentDto)
            )
        )
    }

    override fun getCommentsByApplicationFormId(applicationFormId: UUID): ResponseEntity<PagedCommentDto> {
        return ResponseEntity.ok(
            pagedCommentMapper.toPagedCommentDto(
                commentService.getComments(applicationFormId)
            )
        )
    }

    override fun updateComment(id: UUID, commentDto: CommentDto): ResponseEntity<CommentDto> {
        return ResponseEntity.ok(
            commentMapper.toCommentDto(
                commentService.updateComment(commentDto)
            )
        )
    }

    override fun deleteComment(id: UUID): ResponseEntity<Unit> {
        commentService.deleteCommentByID(id)
        return ResponseEntity.noContent().build()
    }
}
