package de.tsschulz.tt_tagebuch.shared.api.models

fun Member.toSetBody(
    firstname: String,
    lastname: String,
    street: String?,
    city: String?,
    postalCode: String?,
    birthdate: String?,
    phone: String?,
    email: String?,
    active: Boolean,
    testMembership: Boolean,
    picsInInternetAllowed: Boolean,
    gender: String?,
    memberFormHandedOver: Boolean,
    adultReleaseApproved: Boolean,
    adultReserveApproved: Boolean,
    contacts: List<MemberContactSetBody>,
): MemberSetBody = MemberSetBody(
    id = if (id <= 0) null else id,
    firstname = firstname,
    lastname = lastname,
    street = street.orEmpty(),
    city = city.orEmpty(),
    postalCode = postalCode?.ifBlank { null },
    birthdate = birthdate?.ifBlank { null },
    phone = phone.orEmpty(),
    email = email.orEmpty(),
    active = active,
    testMembership = testMembership,
    picsInInternetAllowed = picsInInternetAllowed,
    gender = gender?.ifBlank { null } ?: "unknown",
    ttr = ttr,
    qttr = qttr,
    memberFormHandedOver = memberFormHandedOver,
    adultReleaseApproved = adultReleaseApproved,
    adultReserveApproved = adultReserveApproved,
    contacts = contacts,
)

fun MemberContactDto.toSetBody(): MemberContactSetBody =
    MemberContactSetBody(
        type = type,
        value = value,
        isParent = isParent,
        parentName = parentName,
        isPrimary = isPrimary,
    )
