package com.tt.honeyDue.widget

import androidx.compose.ui.graphics.Color
import org.junit.Assert.assertEquals
import org.junit.Test

/**
 * Unit test for [WidgetColors].
 *
 * Priority color mapping mirrors iOS `OrganicTaskRowView.priorityColor`
 * in `iosApp/HoneyDue/HoneyDue.swift`:
 *
 *  - urgent  → appError
 *  - high    → appAccent
 *  - medium  → yellow
 *  - low     → appPrimary
 *  - overdue → appError (overrides everything else)
 *
 * Priority "level" values match the backend seed in
 * `MyCribAPI_GO/internal/testutil/testutil.go`:
 *  1 = Low, 2 = Medium, 3 = High, 4 = Urgent.
 */
class WidgetColorsTest {

    @Test
    fun colorForPriority_urgent_is_error() {
        assertEquals(WidgetColors.ERROR, WidgetColors.colorForPriority(priorityLevel = 4))
    }

    @Test
    fun colorForPriority_high_is_accent() {
        assertEquals(WidgetColors.ACCENT, WidgetColors.colorForPriority(priorityLevel = 3))
    }

    @Test
    fun colorForPriority_medium_is_yellow() {
        assertEquals(WidgetColors.YELLOW_MEDIUM, WidgetColors.colorForPriority(priorityLevel = 2))
    }

    @Test
    fun colorForPriority_low_is_primary() {
        assertEquals(WidgetColors.PRIMARY, WidgetColors.colorForPriority(priorityLevel = 1))
    }

    @Test
    fun colorForPriority_unknown_defaults_to_primary() {
        // iOS default branch falls through to appPrimary for any non-urgent/high/medium.
        assertEquals(WidgetColors.PRIMARY, WidgetColors.colorForPriority(priorityLevel = 0))
        assertEquals(WidgetColors.PRIMARY, WidgetColors.colorForPriority(priorityLevel = 99))
    }

    @Test
    fun colorForOverdue_true_returns_error() {
        assertEquals(WidgetColors.ERROR, WidgetColors.colorForOverdue(isOverdue = true))
    }

    @Test
    fun colorForOverdue_false_returns_textSecondary() {
        // iOS "Overdue" pill uses appTextSecondary when there's nothing overdue.
        assertEquals(WidgetColors.TEXT_SECONDARY, WidgetColors.colorForOverdue(isOverdue = false))
    }

    @Test
    fun taskRowColor_overdue_beats_priority() {
        // iOS OrganicTaskRowView: `if task.isOverdue { return .appError }` first.
        val c = WidgetColors.taskRowColor(priorityLevel = 1, isOverdue = true)
        assertEquals(WidgetColors.ERROR, c)
    }

    @Test
    fun taskRowColor_not_overdue_uses_priority() {
        assertEquals(
            WidgetColors.ACCENT,
            WidgetColors.taskRowColor(priorityLevel = 3, isOverdue = false)
        )
    }

    @Test
    fun dueDateTextColor_overdue_is_error_otherwise_accent() {
        // iOS: `.foregroundStyle(task.isOverdue ? Color.appError : Color.appAccent)`
        assertEquals(WidgetColors.ERROR, WidgetColors.dueDateTextColor(isOverdue = true))
        assertEquals(WidgetColors.ACCENT, WidgetColors.dueDateTextColor(isOverdue = false))
    }

    @Test
    fun colors_are_stable_instances() {
        // Sanity: make sure the constants aren't null/default — helps catch
        // a refactor that accidentally resets them to Color.Unspecified.
        assertEquals(Color(0xFF07A0C3), WidgetColors.PRIMARY)
        assertEquals(Color(0xFFF5A623), WidgetColors.ACCENT)
        assertEquals(Color(0xFFDD1C1A), WidgetColors.ERROR)
    }
}
