package top.r394realms.ltdmanagertest.whitelist

import io.ktor.http.HttpMethod
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import top.r3944realms.ltdmanager.whitelist.request.WhitelistAction
import top.r3944realms.ltdmanager.whitelist.request.WhitelistActionRequest
import top.r3944realms.ltdmanager.whitelist.request.WhitelistListRequest

class WhitelistRequestTest {

    // ====== WhitelistListRequest ======

    @Test
    fun `list request path`() {
        val req = WhitelistListRequest()
        assertEquals("/api/whitelist/list", req.path())
    }

    @Test
    fun `list request uses GET`() {
        val req = WhitelistListRequest()
        assertEquals(HttpMethod.Get, req.method())
    }

    // ====== WhitelistActionRequest paths ======

    @Test
    fun `approve request path contains player id`() {
        val req = WhitelistActionRequest(42, WhitelistAction.APPROVE)
        assertEquals("/api/whitelist/approve/42", req.path())
    }

    @Test
    fun `reject request path contains player id`() {
        val req = WhitelistActionRequest(7, WhitelistAction.REJECT)
        assertEquals("/api/whitelist/reject/7", req.path())
    }

    @Test
    fun `remove request path contains player id`() {
        val req = WhitelistActionRequest(99, WhitelistAction.REMOVE)
        assertEquals("/api/whitelist/remove/99", req.path())
    }

    // ====== WhitelistActionRequest methods ======

    @Test
    fun `approve request uses POST`() {
        val req = WhitelistActionRequest(1, WhitelistAction.APPROVE)
        assertEquals(HttpMethod.Post, req.method())
    }

    @Test
    fun `reject request uses POST`() {
        val req = WhitelistActionRequest(1, WhitelistAction.REJECT)
        assertEquals(HttpMethod.Post, req.method())
    }

    @Test
    fun `remove request uses DELETE`() {
        val req = WhitelistActionRequest(1, WhitelistAction.REMOVE)
        assertEquals(HttpMethod.Delete, req.method())
    }

    // ====== WhitelistAction enum ======

    @Test
    fun `all actions have distinct operation strings`() {
        val ops = WhitelistAction.entries.map { it.operation }.toSet()
        assertEquals(WhitelistAction.entries.size, ops.size)
    }

    @Test
    fun `action enums cover approve reject remove`() {
        assertEquals(3, WhitelistAction.entries.size)
        assertTrue(WhitelistAction.entries.any { it == WhitelistAction.APPROVE })
        assertTrue(WhitelistAction.entries.any { it == WhitelistAction.REJECT })
        assertTrue(WhitelistAction.entries.any { it == WhitelistAction.REMOVE })
    }

    // ====== shouldRetryOnFailure ======

    @Test
    fun `list request should retry on failure`() {
        val req = WhitelistListRequest()
        assertTrue(req.shouldRetryOnFailure())
    }

    @Test
    fun `action requests should not retry on failure`() {
        val req = WhitelistActionRequest(1, WhitelistAction.REJECT)
        assertFalse(req.shouldRetryOnFailure())
    }
}
