# EnumsToTextModel.kt

    /*
     * The MIT License
     *
     * Original work sponsored and donated by The Danish Health Data Authority (http://www.sundhedsdatastyrelsen.dk)
     *
     * Copyright (C) 2020 The Danish Health Data Authority (http://www.sundhedsdatastyrelsen.dk)
     *
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy of
     * this software and associated documentation files (the "Software"), to deal in
     * the Software without restriction, including without limitation the rights to
     * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
     * of the Software, and to permit persons to whom the Software is furnished to do
     * so, subject to the following conditions:
     *
     *
     * The above copyright notice and this permission notice shall be included in all
     * copies or substantial portions of the Software.
     *
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     * SOFTWARE.
     */

    package dk.nsp.mingraviditet.ui.main.journal.extensions

    import androidx.annotation.StringRes
    import dk.nsp.mingraviditet.R
    import dk.nsp.models.*
    import dk.nsp.util.TextModel
    import dk.nsp.util.TextResourceModel

    fun YesNoEnum?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                YesNoEnum.True -> R.string.enum_yes
                YesNoEnum.False -> R.string.enum_no
                else -> R.string.common_missing_data
            }
        )
    }

    fun PosNegEnum?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                PosNegEnum.Positive -> R.string.enum_positive
                PosNegEnum.Negative -> R.string.enum_negative
                null -> R.string.common_missing_data
            }
        )
    }

    fun PositiveNegativeDeclinedScreeningWithDateSection.Result?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                PositiveNegativeDeclinedScreeningWithDateSection.Result.Positive -> R.string.enum_positive
                PositiveNegativeDeclinedScreeningWithDateSection.Result.Negative -> R.string.enum_negative
                PositiveNegativeDeclinedScreeningWithDateSection.Result.Declined -> R.string.enum_declined
                else -> R.string.common_missing_data
            }
        )
    }

    fun ExpectedDateOfDeliverySectionAllOfExpectedDateOfDeliveryFromLastPeriod.Certainty?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                ExpectedDateOfDeliverySectionAllOfExpectedDateOfDeliveryFromLastPeriod.Certainty.Certain -> R.string.enum_certainty_certain
                ExpectedDateOfDeliverySectionAllOfExpectedDateOfDeliveryFromLastPeriod.Certainty.Equivocal -> R.string.enum_certainty_equivocal
                null -> R.string.common_missing_data
            }
        )
    }

    fun AssistedFertilizationSection.Type?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                AssistedFertilizationSection.Type.Spontaneous -> R.string.assisted_fertilization_type_spontaneous
                AssistedFertilizationSection.Type.OvulationInductionIvf -> R.string.assisted_fertilization_type_ovulation_induction_ivf
                AssistedFertilizationSection.Type.Ivf -> R.string.assisted_fertilization_type_ivf
                AssistedFertilizationSection.Type.Icsi -> R.string.assisted_fertilization_type_icsi
                AssistedFertilizationSection.Type.HormoneTherapy -> R.string.assisted_fertilization_type_hormone_therapy
                AssistedFertilizationSection.Type.Insemination -> R.string.assisted_fertilization_type_insemination
                AssistedFertilizationSection.Type.EggDonation -> R.string.assisted_fertilization_type_egg_donation
                AssistedFertilizationSection.Type.Unknown -> R.string.assisted_fertilization_type_unknown
                null -> R.string.common_missing_data
            }
        )
    }

    fun AllergiesSection.AllergicPredispositionOfChild?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                AllergiesSection.AllergicPredispositionOfChild.NoPredisposition -> R.string.allergic_predisposition_no
                AllergiesSection.AllergicPredispositionOfChild.SinglePredisposition -> R.string.allergic_predisposition_single
                AllergiesSection.AllergicPredispositionOfChild.DoublePredisposition -> R.string.allergic_predisposition_double
                null -> R.string.common_missing_data
            }
        )
    }

    fun List<ChronicDiseasesSection.Conditions>?.toTextModel(): TextModel {
        val conditionsAsTextModels = this?.map {
            TextModel.from(it.toStringRes())
        }?.toTypedArray() ?: arrayOf()

        val commaSeparatedTemplate = conditionsAsTextModels.getCommaSeparatedStringResForSize()

        return TextModel.from(commaSeparatedTemplate, *conditionsAsTextModels)
    }

    fun ChronicDiseasesSection.Conditions.toStringRes(): Int {
        return when (this) {
            ChronicDiseasesSection.Conditions.CirculatorySystem -> R.string.chronic_condition_circulatory_system
            ChronicDiseasesSection.Conditions.RespiratorySystem -> R.string.chronic_condition_respiratory_system
            ChronicDiseasesSection.Conditions.Thyroid -> R.string.chronic_condition_thyroid
            ChronicDiseasesSection.Conditions.Diabetes -> R.string.chronic_condition_diabetes
            ChronicDiseasesSection.Conditions.Epilepsy -> R.string.chronic_condition_epilepsy
            ChronicDiseasesSection.Conditions.MentalIllness -> R.string.chronic_condition_mental_illness
            ChronicDiseasesSection.Conditions.Herpes -> R.string.chronic_condition_herpes
            ChronicDiseasesSection.Conditions.Uvi -> R.string.chronic_condition_uvi
            ChronicDiseasesSection.Conditions.ConeSection -> R.string.chronic_condition_cone_section
            ChronicDiseasesSection.Conditions.Mrsa -> R.string.chronic_condition_mrsa
            ChronicDiseasesSection.Conditions.Gbs -> R.string.chronic_condition_gbs
        }
    }

    private fun Array<TextResourceModel>.getCommaSeparatedStringResForSize(): Int {
        return when (this.size) {
            0 -> R.string.zero_items_comma_divided
            1 -> R.string.one_item_comma_divided
            2 -> R.string.two_items_comma_divided
            3 -> R.string.three_items_comma_divided
            4 -> R.string.four_items_comma_divided
            5 -> R.string.five_items_comma_divided
            6 -> R.string.six_items_comma_divided
            7 -> R.string.seven_items_comma_divided
            8 -> R.string.eight_items_comma_divided
            9 -> R.string.nine_items_comma_divided
            10 -> R.string.ten_items_comma_divided
            11 -> R.string.eleven_items_comma_divided
            else -> R.string.zero_items_comma_divided
        }
    }

    fun MmrVaccinationSection.Status?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                MmrVaccinationSection.Status.Vaccinated -> R.string.vaccination_status_vaccinated
                MmrVaccinationSection.Status.NotVaccinated -> R.string.vaccination_status_not_vaccinated
                MmrVaccinationSection.Status.Unknown -> R.string.vaccination_status_unknown
                null -> R.string.common_missing_data
            }
        )
    }

    fun TobaccoUseAndExposureSection.TobaccoUser?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                TobaccoUseAndExposureSection.TobaccoUser.Active -> R.string.tobacco_usage_active
                TobaccoUseAndExposureSection.TobaccoUser.Never -> R.string.tobacco_usage_never
                TobaccoUseAndExposureSection.TobaccoUser.FormerBecausePregnancy -> R.string.tobacco_usage_former_because_pregnancy
                TobaccoUseAndExposureSection.TobaccoUser.FormerLongAgo -> R.string.tobacco_usage_former_long_ago
                null -> R.string.common_missing_data
            }
        )
    }

    @StringRes
    fun WorkEnvironmentImpactSectionAllOfMotherExposureToWorkEnvironmentRisk.Types.toStringRes(): Int {
        return when (this) {
            WorkEnvironmentImpactSectionAllOfMotherExposureToWorkEnvironmentRisk.Types.Biological -> R.string.work_environment_risk_type_biological
            WorkEnvironmentImpactSectionAllOfMotherExposureToWorkEnvironmentRisk.Types.Chemical -> R.string.work_environment_risk_type_chemical
            WorkEnvironmentImpactSectionAllOfMotherExposureToWorkEnvironmentRisk.Types.Ergonomic -> R.string.work_environment_risk_type_ergonomic
            WorkEnvironmentImpactSectionAllOfMotherExposureToWorkEnvironmentRisk.Types.Other -> R.string.work_environment_risk_type_other
        }
    }

    fun List<WorkEnvironmentImpactSectionAllOfMotherExposureToWorkEnvironmentRisk.Types>?.toCommaSeparatedTextModel(): TextModel {
        val conditionsAsTextModels = this?.map {
            TextModel.from(it.toStringRes())
        }?.toTypedArray() ?: arrayOf()

        val commaSeparatedTemplate = conditionsAsTextModels.getCommaSeparatedStringResForSize()

        return TextModel.from(commaSeparatedTemplate, *conditionsAsTextModels)
    }

    fun WorkEnvironmentImpactSectionAllOfMother.PrenatalSickLeave?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                WorkEnvironmentImpactSectionAllOfMother.PrenatalSickLeave.None -> R.string.prenatal_sick_leave_none
                WorkEnvironmentImpactSectionAllOfMother.PrenatalSickLeave.Partial -> R.string.prenatal_sick_leave_partial
                WorkEnvironmentImpactSectionAllOfMother.PrenatalSickLeave.Full -> R.string.prenatal_sick_leave_full
                null -> R.string.common_missing_data
            }
        )
    }

    fun PreviousBirthsSectionAllOfChildren.Sex?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                PreviousBirthsSectionAllOfChildren.Sex.Female -> R.string.child_sex_female
                PreviousBirthsSectionAllOfChildren.Sex.Male -> R.string.child_sex_male
                null -> R.string.common_missing_data
            }
        )
    }

    fun PreviousBirthsSectionAllOfChildren.Outcome?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                PreviousBirthsSectionAllOfChildren.Outcome.Livebirth -> R.string.child_outcome_livebirth
                PreviousBirthsSectionAllOfChildren.Outcome.Stillbirth -> R.string.child_outcome_stillbirth
                null -> R.string.common_missing_data
            }
        )
    }

    fun PreviousBirthsSectionAllOfBirths.SubjectiveBirthExperience?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                PreviousBirthsSectionAllOfBirths.SubjectiveBirthExperience.Good -> R.string.subjective_experience_good
                PreviousBirthsSectionAllOfBirths.SubjectiveBirthExperience.Normal -> R.string.subjective_experience_normal
                PreviousBirthsSectionAllOfBirths.SubjectiveBirthExperience.Bad -> R.string.subjective_experience_bad
                null -> R.string.common_missing_data
            }
        )
    }

    fun PreviousAbortionsSectionAllOfAbortions.Type?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                PreviousAbortionsSectionAllOfAbortions.Type.Spontaneous -> R.string.abortion_type_spontaneous
                PreviousAbortionsSectionAllOfAbortions.Type.Induced -> R.string.abortion_type_induced
                null -> R.string.common_missing_data
            }
        )
    }

    fun MidwifeClinicSectionAllOfParentalCraftClassDesired.ConsultationForm?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                MidwifeClinicSectionAllOfParentalCraftClassDesired.ConsultationForm.Individual -> R.string.midwife_consultation_form_individual
                MidwifeClinicSectionAllOfParentalCraftClassDesired.ConsultationForm.Group -> R.string.midwife_consultation_form_group
                null -> R.string.common_missing_data
            }
        )
    }

    fun SocialHistorySection.MaritalOrPartnershipStatus?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                SocialHistorySection.MaritalOrPartnershipStatus.Single -> R.string.partnership_status_single
                SocialHistorySection.MaritalOrPartnershipStatus.Married -> R.string.partnership_status_married
                SocialHistorySection.MaritalOrPartnershipStatus.Separated -> R.string.partnership_status_separated
                SocialHistorySection.MaritalOrPartnershipStatus.Divorced -> R.string.partnership_status_divorced
                SocialHistorySection.MaritalOrPartnershipStatus.Widowed -> R.string.partnership_status_widowed
                null -> R.string.common_missing_data
            }
        )
    }

    fun SocialHistorySection.LivingConditions?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                SocialHistorySection.LivingConditions.Partnership -> R.string.living_conditions_partnership
                SocialHistorySection.LivingConditions.Single -> R.string.living_conditions_single
                null -> R.string.common_missing_data
            }
        )
    }

    fun OverallAssessmentSectionAllOfPrenatalCareAssessment.CareLevel?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                OverallAssessmentSectionAllOfPrenatalCareAssessment.CareLevel.Basic -> R.string.prenatal_carelevel_basic
                OverallAssessmentSectionAllOfPrenatalCareAssessment.CareLevel.Extended -> R.string.prenatal_carelevel_extended
                OverallAssessmentSectionAllOfPrenatalCareAssessment.CareLevel.SpecialistMultidisciplinaryTeam -> R.string.prenatal_carelevel_specialist_multidisciplinary_team
                OverallAssessmentSectionAllOfPrenatalCareAssessment.CareLevel.HighRiskPregnancyCare -> R.string.prenatal_carelevel_high_rish_pregnancy_care
                null -> R.string.common_missing_data
            }
        )
    }

    fun RiskAssessment3.DownsScreeningProbabilityAssessment?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                RiskAssessment3.DownsScreeningProbabilityAssessment.High -> R.string.probability_assessment_high
                RiskAssessment3.DownsScreeningProbabilityAssessment.Low -> R.string.probability_assessment_low
                null -> R.string.common_missing_data
            }
        )
    }

    fun MidwifeConsultationSectionAllOfMidwifeConsultationWishes.Weekday?.toTextModel(): TextModel {
        return TextModel.from(
            when (this) {
                MidwifeConsultationSectionAllOfMidwifeConsultationWishes.Weekday.Monday -> R.string.midwife_weekday_wish_monday
                MidwifeConsultationSectionAllOfMidwifeConsultationWishes.Weekday.Tuesday -> R.string.midwife_weekday_wish_tuesday
                MidwifeConsultationSectionAllOfMidwifeConsultationWishes.Weekday.Wednesday -> R.string.midwife_weekday_wish_wednesday
                MidwifeConsultationSectionAllOfMidwifeConsultationWishes.Weekday.Thursday -> R.string.midwife_weekday_wish_thursday
                MidwifeConsultationSectionAllOfMidwifeConsultationWishes.Weekday.Friday -> R.string.midwife_weekday_wish_friday
                MidwifeConsultationSectionAllOfMidwifeConsultationWishes.Weekday.Saturday -> R.string.midwife_weekday_wish_saturday
                MidwifeConsultationSectionAllOfMidwifeConsultationWishes.Weekday.Sunday -> R.string.midwife_weekday_wish_sunday
                null -> R.string.common_missing_data
            }
        )
    }