// config/helper/CustomerInfoFieldMapper.kt package com.complycube.reactnative.config.helper import com.complycube.sdk.data.remote.model.response.ComponentFormat import com.complycube.sdk.data.remote.model.response.ComponentType import com.complycube.sdk.data.remote.model.response.Constraint import com.complycube.sdk.data.remote.model.response.QuestionItemComponentFormat import com.complycube.sdk.data.remote.model.response.QuestionOptionsItem import com.complycube.sdk.common.data.CustomerInfoDetail import com.complycube.sdk.common.data.CustomerInfoField import com.complycube.sdk.common.data.CustomerInfoPersonField import com.complycube.sdk.common.data.CustomerInfoCompanyField class CustomerInfoFieldMapper { fun mapStringField(field: String): CustomerInfoField? { return when (field) { "email" -> CustomerInfoField.Email "mobile" -> CustomerInfoField.Mobile "joined_date" -> CustomerInfoField.JoinedDate "telephone" -> CustomerInfoField.Telephone "external_id" -> CustomerInfoField.ExternalId else -> null } } fun mapPersonFields(personList: List<*>): List { return personList.mapNotNull { entry -> when (entry) { is String -> mapPersonField(entry) is Map<*, *> -> { val name = entry["name"] as? String ?: return@mapNotNull null val constraint = (entry["constraint"] as? Map<*, *>)?.let { val expr = it["expression"] as? String ?: return@let null Constraint(expr) } mapPersonField(name)?.copy(constraint = constraint) } else -> null } } } fun mapCompanyFields(companyList: List<*>): List { return companyList.mapNotNull { entry -> when (entry) { is String -> mapCompanyField(entry) is Map<*, *> -> { val name = entry["name"] as? String ?: return@mapNotNull null val constraint = (entry["constraint"] as? Map<*, *>)?.let { val expr = it["expression"] as? String ?: return@let null Constraint(expr) } mapCompanyField(name)?.copy(constraint = constraint) } else -> null } } } private fun mapPersonField(name: String): CustomerInfoPersonField? { return when (name) { "first_name" -> CustomerInfoPersonField.FIRST_NAME "middle_name" -> CustomerInfoPersonField.MIDDLE_NAME "last_name" -> CustomerInfoPersonField.LAST_NAME "gender" -> CustomerInfoPersonField.GENDER "date_of_birth" -> CustomerInfoPersonField.DATE_OF_BIRTH "birth_country" -> CustomerInfoPersonField.BIRTH_COUNTRY "nationality" -> CustomerInfoPersonField.NATIONALITY "national_id" -> CustomerInfoPersonField.NATIONAL_IDENTITY_NUMBER "social_insurance_number" -> CustomerInfoPersonField.SOCIAL_INSURANCE_NUMBER "ssn" -> CustomerInfoPersonField.SSN "tax_identification_number" -> CustomerInfoPersonField.TAX_IDENTIFICATION_NUMBER else -> null } } private fun mapCompanyField(name: String): CustomerInfoCompanyField? { return when (name) { "name" -> CustomerInfoCompanyField.NAME "website" -> CustomerInfoCompanyField.WEBSITE "registration_number" -> CustomerInfoCompanyField.REGISTRATION_NUMBER "incorporation_type" -> CustomerInfoCompanyField.INCORPORATION_TYPE "incorporation_country" -> CustomerInfoCompanyField.INCORPORATION_COUNTRY else -> null } } }