package com.betriebsratkanzlei.legalconsenthub.application_form_template

import com.betriebsratkanzlei.legalconsenthub.application_form.ApplicationFormMapper
import com.betriebsratkanzlei.legalconsenthub.application_form.PagedApplicationFormMapper
import com.betriebsratkanzlei.legalconsenthub_api.api.ApplicationFormTemplateApi
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.PagedApplicationFormDto
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RestController
import java.util.UUID

@RestController
class ApplicationFormTemplateController(
    val applicationFormTemplateService: ApplicationFormTemplateService,
    val pagedApplicationFormMapper: PagedApplicationFormMapper,
    val applicationFormMapper: ApplicationFormMapper,
) : ApplicationFormTemplateApi {

    override fun createApplicationFormTemplate(createApplicationFormDto: CreateApplicationFormDto): ResponseEntity<ApplicationFormDto> {
        return ResponseEntity.ok(
            applicationFormMapper.toApplicationFormDto(
                applicationFormTemplateService.createApplicationFormTemplate(createApplicationFormDto)
            )
        )
    }

    override fun getAllApplicationFormTemplates(): ResponseEntity<PagedApplicationFormDto> {
        return ResponseEntity.ok(
            pagedApplicationFormMapper.toPagedApplicationFormDto(
                applicationFormTemplateService.getApplicationFormTemplates()
            )
        )
    }

    override fun getApplicationFormTemplateById(id: UUID): ResponseEntity<ApplicationFormDto> {
        return ResponseEntity.ok(
            applicationFormMapper.toApplicationFormDto(
                applicationFormTemplateService.getApplicationFormTemplateById(id)
            )
        )
    }

    override fun updateApplicationFormTemplate(
        id: UUID,
        applicationFormDto: ApplicationFormDto
    ): ResponseEntity<ApplicationFormDto> {
        return ResponseEntity.ok(
            applicationFormMapper.toApplicationFormDto(
                applicationFormTemplateService.updateApplicationFormTemplate(applicationFormDto)
            )
        )
    }

    override fun deleteApplicationFormTemplate(id: UUID): ResponseEntity<Unit> {
        applicationFormTemplateService.deleteApplicationFormTemplateByID(id)
        return ResponseEntity.noContent().build()
    }
}
