package com.tt.honeyDue.ui.screens.task

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

/**
 * Pure-function validator tests for TaskFormValidation.
 *
 * Error strings are copied verbatim from
 * `iosApp/iosApp/Task/TaskFormView.swift::validateForm()`
 * and `iosApp/iosApp/Core/FormStates/TaskFormStates.swift`.
 */
class TaskFormValidationTest {

    // --- validateTitle ------------------------------------------------------

    @Test
    fun validateTitle_emptyString_returnsTitleRequired() {
        assertEquals("Title is required", TaskFormValidation.validateTitle(""))
    }

    @Test
    fun validateTitle_blankString_returnsTitleRequired() {
        assertEquals("Title is required", TaskFormValidation.validateTitle("   "))
    }

    @Test
    fun validateTitle_nonEmpty_returnsNull() {
        assertNull(TaskFormValidation.validateTitle("Change air filter"))
    }

    // --- validatePriorityId -------------------------------------------------

    @Test
    fun validatePriorityId_null_returnsPleaseSelectPriority() {
        assertEquals(
            "Please select a priority",
            TaskFormValidation.validatePriorityId(null)
        )
    }

    @Test
    fun validatePriorityId_set_returnsNull() {
        assertNull(TaskFormValidation.validatePriorityId(1))
    }

    // --- validateCategoryId -------------------------------------------------

    @Test
    fun validateCategoryId_null_returnsPleaseSelectCategory() {
        assertEquals(
            "Please select a category",
            TaskFormValidation.validateCategoryId(null)
        )
    }

    @Test
    fun validateCategoryId_set_returnsNull() {
        assertNull(TaskFormValidation.validateCategoryId(2))
    }

    // --- validateFrequencyId ------------------------------------------------

    @Test
    fun validateFrequencyId_null_returnsPleaseSelectFrequency() {
        assertEquals(
            "Please select a frequency",
            TaskFormValidation.validateFrequencyId(null)
        )
    }

    @Test
    fun validateFrequencyId_set_returnsNull() {
        assertNull(TaskFormValidation.validateFrequencyId(3))
    }

    // --- validateEstimatedCost ---------------------------------------------

    @Test
    fun validateEstimatedCost_empty_returnsNull() {
        assertNull(TaskFormValidation.validateEstimatedCost(""))
    }

    @Test
    fun validateEstimatedCost_validInteger_returnsNull() {
        assertNull(TaskFormValidation.validateEstimatedCost("100"))
    }

    @Test
    fun validateEstimatedCost_validDecimal_returnsNull() {
        assertNull(TaskFormValidation.validateEstimatedCost("49.99"))
    }

    @Test
    fun validateEstimatedCost_nonNumeric_returnsError() {
        assertEquals(
            "Estimated cost must be a valid number",
            TaskFormValidation.validateEstimatedCost("abc")
        )
    }

    // --- validateResidenceId -----------------------------------------------

    @Test
    fun validateResidenceId_null_returnsPropertyRequired() {
        assertEquals(
            "Property is required",
            TaskFormValidation.validateResidenceId(null)
        )
    }

    @Test
    fun validateResidenceId_set_returnsNull() {
        assertNull(TaskFormValidation.validateResidenceId(5))
    }
}
