package com.prodhack.moscow2025.presentation.screens.fillProfile

import com.prodhack.moscow2025.domain.models.PhoneNumberPattern

data class UIPhoneNumberPattern(
	val prefix: String,
	val name: String,
	val countryCode: String,
	val pattern: String,
	val countryCodeISO: String
) {
	fun mapToDomain(): PhoneNumberPattern = PhoneNumberPattern(
		name = name,
		countryCode = countryCode,
		countryCodeISO = countryCodeISO,
		pattern = pattern
	)
}

fun PhoneNumberPattern.mapToUI(): UIPhoneNumberPattern = UIPhoneNumberPattern(
	name = name,
	countryCode = countryCode,
	countryCodeISO = countryCodeISO,
	pattern = pattern,
	prefix = getFlagEmoji(countryCodeISO) + " " + countryCode
)

fun getFlagEmoji(code: String): String {
	val firstLetter = Character.codePointAt(code, 0) - 0x41 + 0x1F1E6
	val secondLetter = Character.codePointAt(code, 1) - 0x41 + 0x1F1E6
	return String(Character.toChars(firstLetter)) + String(Character.toChars(secondLetter))
}