package com.prodhack.moscow2025.presentation.utils

import androidx.compose.ui.text.AnnotatedString
import com.prodhack.moscow2025.domain.models.PhoneNumberPattern
import org.junit.Test
import org.junit.Assert.*

class PhoneTransformationTest {

	@Test
	fun `convertNumberToPattern formats Russian number correctly`() {
		val pattern = PhoneNumberPattern(
			name = "+7 Россия",
			countryCode = "+7",
			pattern = "(000)-000-00-00",
			countryCodeISO = "RU"
		)
		val number = "9123456789"
		val result = convertNumberToPattern(pattern, number)
		assertEquals("+7 (912)-345-67-89", result)
	}

	@Test
	fun `convertNumberToPattern formats US number correctly`() {
		val pattern = PhoneNumberPattern(
			name = "+1 США",
			countryCode = "+1",
			pattern = "(000) 000-0000",
			countryCodeISO = "US"
		)
		val number = "5551234567"
		val result = convertNumberToPattern(pattern, number)
		assertEquals("+1 (555) 123-4567", result)
	}

	@Test
	fun `convertNumberToPattern handles short number`() {
		val pattern = PhoneNumberPattern(
			name = "Test",
			countryCode = "+1",
			pattern = "000-0000",
			countryCodeISO = "US"
		)
		val number = "1234567"
		val result = convertNumberToPattern(pattern, number)
		assertEquals("+1 123-4567", result)
	}

	@Test
	fun `PhoneVisualTransformation filters text correctly`() {
		val transformation = PhoneVisualTransformation(mask = "(000) 000-0000", maskNumber = '0')
		val input = AnnotatedString("1234567890")
		val result = transformation.filter(input)
		assertNotNull(result)
		assertTrue(result.text.text.isNotEmpty())
	}

	@Test
	fun `PhoneVisualTransformation handles empty input`() {
		val transformation = PhoneVisualTransformation(mask = "(000) 000-0000", maskNumber = '0')
		val input = AnnotatedString("")
		val result = transformation.filter(input)
		assertNotNull(result)
	}

	@Test
	fun `PhoneVisualTransformation handles long input`() {
		val transformation = PhoneVisualTransformation(mask = "(000) 000-0000", maskNumber = '0')
		val input = AnnotatedString("12345678901234567890") // Longer than mask
		val result = transformation.filter(input)
		assertNotNull(result)
		assertTrue(result.text.text.length <= "(000) 000-0000".length)
	}

	@Test
	fun `PhoneVisualTransformation equals works correctly`() {
		val transformation1 = PhoneVisualTransformation(mask = "(000) 000-0000", maskNumber = '0')
		val transformation2 = PhoneVisualTransformation(mask = "(000) 000-0000", maskNumber = '0')
		val transformation3 = PhoneVisualTransformation(mask = "000-0000", maskNumber = '0')

		assertEquals(transformation1, transformation2)
		assertNotEquals(transformation1, transformation3)
	}

	@Test
	fun `PhoneVisualTransformation hashCode works correctly`() {
		val transformation1 = PhoneVisualTransformation(mask = "(000) 000-0000", maskNumber = '0')
		val transformation2 = PhoneVisualTransformation(mask = "(000) 000-0000", maskNumber = '0')
		assertEquals(transformation1.hashCode(), transformation2.hashCode())
	}
}

