package com.betriebsratkanzlei.legalconsenthub.notification

import com.betriebsratkanzlei.legalconsenthub.user.UserMapper
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateNotificationDto
import com.betriebsratkanzlei.legalconsenthub_api.model.NotificationDto
import org.springframework.stereotype.Component

@Component
class NotificationMapper(
    private val userMapper: UserMapper
) {

    fun toNotificationDto(notification: Notification): NotificationDto {
        return NotificationDto(
            id = notification.id!!,
            title = notification.title,
            message = notification.message,
            clickTarget = notification.clickTarget,
            isRead = notification.isRead,
            recipient = notification.recipient?.let { userMapper.toUserDto(it) },
            role = notification.role,
            type = notification.type,
            organizationId = notification.organizationId,
            createdAt = notification.createdAt!!
        )
    }

    fun toNotification(createNotificationDto: CreateNotificationDto): Notification {
        return Notification(
            title = createNotificationDto.title,
            message = createNotificationDto.message,
            clickTarget = createNotificationDto.clickTarget,
            isRead = false,
            recipient = createNotificationDto.recipient?.let { userMapper.toUser(it) },
            role = createNotificationDto.role,
            type = createNotificationDto.type,
            organizationId = createNotificationDto.organizationId
        )
    }
}
