/*
 * Copyright (c) 2025 Element Creations Ltd.
 * Copyright 2025 New Vector Ltd.
 *
 * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
 * Please see LICENSE files in the repository root for full details.
 */

package id.databisnis.android.bachot.features.forward.impl

import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.bumble.appyx.core.modality.BuildContext
import com.bumble.appyx.testing.junit4.util.MainDispatcherRule
import com.google.common.truth.Truth.assertThat
import id.databisnis.android.bachot.features.forward.api.ForwardEntryPoint
import id.databisnis.android.bachot.libraries.matrix.api.core.RoomId
import id.databisnis.android.bachot.libraries.matrix.test.AN_EVENT_ID
import id.databisnis.android.bachot.libraries.matrix.test.timeline.FakeTimelineProvider
import id.databisnis.android.bachot.libraries.roomselect.test.FakeRoomSelectEntryPoint
import id.databisnis.android.bachot.tests.testutils.lambda.lambdaError
import id.databisnis.android.bachot.tests.testutils.node.TestParentNode
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test

class DefaultForwardEntryPointTest {
    @get:Rule
    val instantTaskExecutorRule = InstantTaskExecutorRule()

    @get:Rule
    val mainDispatcherRule = MainDispatcherRule()

    @Test
    fun `test node builder`() = runTest {
        val entryPoint = DefaultForwardEntryPoint()
        val parentNode = TestParentNode.create { buildContext, plugins ->
            ForwardMessagesNode(
                buildContext = buildContext,
                plugins = plugins,
                presenterFactory = { _, _ -> createForwardMessagesPresenter() },
                roomSelectEntryPoint = FakeRoomSelectEntryPoint(),
            )
        }
        val callback = object : ForwardEntryPoint.Callback {
            override fun onDone(roomIds: List<RoomId>) = lambdaError()
        }
        val params = ForwardEntryPoint.Params(
            eventId = AN_EVENT_ID,
            timelineProvider = FakeTimelineProvider(),
        )
        val result = entryPoint.createNode(
            parentNode = parentNode,
            buildContext = BuildContext.root(null),
            params = params,
            callback = callback,
        )
        assertThat(result).isInstanceOf(ForwardMessagesNode::class.java)
        assertThat(result.plugins).contains(
            ForwardMessagesNode.Inputs(
                eventId = params.eventId,
                timelineProvider = params.timelineProvider,
            )
        )
        assertThat(result.plugins).contains(callback)
    }
}
