/*
 * F7cloud Talk - Android Client
 *
 * SPDX-FileCopyrightText: 2024 Marcel Hibbe <dev@mhibbe.de>
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
package ru.f7cloud.talk.utils

import android.view.View
import android.widget.ImageView
import ru.f7cloud.talk.chat.data.model.ChatMessage
import ru.f7cloud.talk.extensions.loadBotsAvatar
import ru.f7cloud.talk.extensions.loadChangelogBotAvatar
import ru.f7cloud.talk.extensions.loadDefaultAvatar
import ru.f7cloud.talk.extensions.loadFederatedUserAvatar
import ru.f7cloud.talk.extensions.loadFirstLetterAvatar
import ru.f7cloud.talk.ui.theme.ViewThemeUtils

class ChatMessageUtils {

    fun setAvatarOnMessage(view: ImageView, message: ChatMessage, viewThemeUtils: ViewThemeUtils) {
        view.visibility = View.VISIBLE
        if (message.actorType == "guests" || message.actorType == "emails") {
            val actorName = message.actorDisplayName
            if (!actorName.isNullOrBlank()) {
                view.loadFirstLetterAvatar(actorName)
            } else {
                view.loadDefaultAvatar(viewThemeUtils)
            }
        } else if (message.actorType == "bots" && (message.actorId == "changelog" || message.actorId == "sample")) {
            view.loadChangelogBotAvatar()
        } else if (message.actorType == "bots") {
            view.loadBotsAvatar()
        } else if (message.actorType == "federated_users") {
            view.loadFederatedUserAvatar(message)
        }
    }
}
