package de.trainingstagebuch.app.utils

import de.trainingstagebuch.app.repository.MemberItem
import org.junit.Assert.assertEquals
import org.junit.Test

class MembersFilterUtilsTest {

    @Test
    fun `apply filters inactive and search query`() {
        val items = listOf(
            MemberItem(id = "1", firstName = "Max", lastName = "Mustermann", displayName = "Max Mustermann", active = true, testMembership = false),
            MemberItem(id = "2", firstName = "Eva", lastName = "Muster", displayName = "Eva Muster", active = false, testMembership = false),
            MemberItem(id = "3", firstName = "Erik", lastName = "Beispiel", displayName = "Erik Beispiel", active = true, testMembership = true)
        )

        val result = MembersFilterUtils.apply(
            members = items,
            searchQuery = "mu",
            showInactive = false,
            sortOrder = MembersSortOrder.NameAsc
        )

        assertEquals(1, result.size)
        assertEquals("Max Mustermann", result.first().displayName)
    }

    @Test
    fun `apply status sort orders active then test then inactive`() {
        val items = listOf(
            MemberItem(id = "1", firstName = "C", lastName = "Inactive", displayName = "C Inactive", active = false, testMembership = false),
            MemberItem(id = "2", firstName = "B", lastName = "Test", displayName = "B Test", active = true, testMembership = true),
            MemberItem(id = "3", firstName = "A", lastName = "Active", displayName = "A Active", active = true, testMembership = false)
        )

        val result = MembersFilterUtils.apply(
            members = items,
            searchQuery = "",
            showInactive = true,
            sortOrder = MembersSortOrder.Status
        )

        assertEquals(listOf("A Active", "B Test", "C Inactive"), result.map { it.displayName })
    }
}
