/*
 * F7cloud Talk - Android Client
 *
 * SPDX-FileCopyrightText: 2024 Christian Reiner <foss@christian-reiner.info>
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

package ru.f7cloud.talk.adapters.messages

import android.widget.RelativeLayout
import androidx.viewbinding.ViewBinding
import ru.f7cloud.talk.databinding.ItemCustomOutcomingDeckCardMessageBinding
import ru.f7cloud.talk.databinding.ItemCustomOutcomingLinkPreviewMessageBinding
import ru.f7cloud.talk.databinding.ItemCustomOutcomingLocationMessageBinding
import ru.f7cloud.talk.databinding.ItemCustomOutcomingPollMessageBinding
import ru.f7cloud.talk.databinding.ItemCustomOutcomingTextMessageBinding
import ru.f7cloud.talk.databinding.ItemCustomOutcomingVoiceMessageBinding
import ru.f7cloud.talk.models.domain.ConversationModel
import ru.f7cloud.talk.models.json.conversations.ConversationEnums.ConversationType

interface AdjustableMessageHolderInterface {

    val binding: ViewBinding

    fun adjustIfNoteToSelf(currentConversation: ConversationModel?) {
        if (currentConversation?.type == ConversationType.NOTE_TO_SELF) {
            when (this.binding.javaClass) {
                ItemCustomOutcomingTextMessageBinding::class.java ->
                    (this.binding as ItemCustomOutcomingTextMessageBinding).bubble
                ItemCustomOutcomingDeckCardMessageBinding::class.java ->
                    (this.binding as ItemCustomOutcomingDeckCardMessageBinding).bubble
                ItemCustomOutcomingLinkPreviewMessageBinding::class.java ->
                    (this.binding as ItemCustomOutcomingLinkPreviewMessageBinding).bubble
                ItemCustomOutcomingPollMessageBinding::class.java ->
                    (this.binding as ItemCustomOutcomingPollMessageBinding).bubble
                ItemCustomOutcomingVoiceMessageBinding::class.java ->
                    (this.binding as ItemCustomOutcomingVoiceMessageBinding).bubble
                ItemCustomOutcomingLocationMessageBinding::class.java ->
                    (this.binding as ItemCustomOutcomingLocationMessageBinding).bubble
                else -> null
            }?.let {
                RelativeLayout.LayoutParams(binding.root.layoutParams).apply {
                    marginStart = 0
                    marginEnd = 0
                }.run {
                    it.layoutParams = this
                }
            }
        }
    }
}
