package com.swoosh.microblog.data.model

import org.junit.Assert.*
import org.junit.Test

class GhostAccountTest {

    @Test
    fun `GhostAccount has correct default values`() {
        val account = GhostAccount(
            id = "test-id",
            name = "Test Blog",
            blogUrl = "https://test.ghost.io",
            apiKey = "key:secret"
        )
        assertFalse(account.isActive)
        assertEquals(0, account.colorIndex)
    }

    @Test
    fun `GhostAccount preserves all fields`() {
        val account = GhostAccount(
            id = "id-123",
            name = "My Blog",
            blogUrl = "https://myblog.com",
            apiKey = "abc:def",
            isActive = true,
            colorIndex = 3
        )
        assertEquals("id-123", account.id)
        assertEquals("My Blog", account.name)
        assertEquals("https://myblog.com", account.blogUrl)
        assertEquals("abc:def", account.apiKey)
        assertTrue(account.isActive)
        assertEquals(3, account.colorIndex)
    }

    @Test
    fun `ACCOUNT_COLORS has 5 colors`() {
        assertEquals(5, GhostAccount.ACCOUNT_COLORS.size)
    }

    @Test
    fun `colorForIndex wraps around for large indices`() {
        val color0 = GhostAccount.colorForIndex(0)
        val color5 = GhostAccount.colorForIndex(5)
        assertEquals(color0, color5)
    }

    @Test
    fun `colorForIndex returns different colors for different indices`() {
        val colors = (0 until 5).map { GhostAccount.colorForIndex(it) }.toSet()
        assertEquals(5, colors.size)
    }

    @Test
    fun `copy preserves fields correctly`() {
        val original = GhostAccount(
            id = "id",
            name = "Name",
            blogUrl = "https://blog.com",
            apiKey = "key:secret",
            isActive = true,
            colorIndex = 2
        )
        val copy = original.copy(name = "New Name")
        assertEquals("New Name", copy.name)
        assertEquals("id", copy.id)
        assertEquals("https://blog.com", copy.blogUrl)
        assertEquals("key:secret", copy.apiKey)
        assertTrue(copy.isActive)
        assertEquals(2, copy.colorIndex)
    }
}
