package de.tsschulz.tt_tagebuch.shared.api.models

import kotlinx.serialization.Serializable

@Serializable
data class DiaryMemberNoteDto(
    val id: Int,
    val memberId: Int? = null,
    val diaryDateId: Int? = null,
    val content: String? = null,
    val createdAt: String? = null,
)

@Serializable
data class DiaryTagNested(
    val id: Int,
    val name: String? = null,
    val label: String? = null,
)

@Serializable
data class DiaryMemberTagLinkDto(
    val id: Int,
    val memberId: Int? = null,
    val diaryDateId: Int? = null,
    val tagId: Int? = null,
    val tag: DiaryTagNested? = null,
)

fun DiaryMemberTagLinkDto.tagDefinitionId(): Int = tag?.id ?: tagId ?: 0

fun DiaryMemberTagLinkDto.tagDisplayName(): String {
    val fromNested = tag?.label?.takeIf { it.isNotBlank() } ?: tag?.name?.takeIf { it.isNotBlank() }
    if (!fromNested.isNullOrBlank()) return fromNested
    val tid = tagDefinitionId()
    return if (tid > 0) "Tag $tid" else "Tag"
}

@Serializable
data class AddDiaryMemberNoteBody(
    val memberId: Int,
    val diaryDateId: Int,
    val content: String,
)

@Serializable
data class DiaryMemberTagMutationBody(
    val diaryDateId: Int,
    val memberId: Int,
    val tagId: Int,
)
