All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.lancom.openapi.entity.Contact.kt Maven / Gradle / Ivy

Go to download

This open-source project provides an OpenAPI 3.0 Parser implemented in Kotlin, utilizing immutable data classes

There is a newer version: 2.1.1
Show newest version
/*****************************************************************************
**   C A U T I O N                                                          **
**   This file is auto-generated!                                           **
**   If you want to make changes, please see the README.md file.            **
**   Please do not edit this file directly!                                 **
*****************************************************************************/
package de.lancom.openapi.entity

import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import de.lancom.openapi.field.Field
import de.lancom.openapi.jackson.EntityDeserializer
import de.lancom.openapi.jackson.EntitySerializer
import de.lancom.openapi.jackson.Parser
import de.lancom.openapi.jackson.Wrapper
import de.lancom.openapi.tools.toYamlString

// hint:9A1BF04C
@Suppress("PropertyName")
@JsonSerialize(using = Contact.Companion.Serializer::class)
@JsonDeserialize(using = Contact.Companion.Deserializer::class)
data class Contact(
    val _name: Field = Field.unset(),
    val _url: Field = Field.unset(),
    val _email: Field = Field.unset(),
    val _extensions: Field> = Field.unset(),
) : Entity {

    ///////////////////////
    //
    // name
    //
    ///////////////////////

    // hint:3A7F9B2E
    val name: String?
        get() = _name.orNull

    // hint:F0C48D71
    fun setNameField(name: Field): Contact {
        return copy(_name = name)
    }

    // hint:8E56A4D9
    fun updateNameField(updater: (Field) -> Field): Contact {
        return setNameField(updater(_name))
    }

    // hint:B1D730FC
    fun updateName(updater: (String?) -> String?): Contact {
        return updateNameField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeNameField(nameFieldToMerge: Field): Contact {
        return mergeName(nameFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeName(nameToMerge: String?): Contact {
        return if (nameToMerge == null) {
            this
        } else {
            val oldName = _name.orNull
            if (oldName == null) {
                setNameField(Field(nameToMerge))
            } else {
                // hint:2F684DAC
                setName(nameToMerge)
            }
        }
    }

    // hint:87B3E19C
    fun setName(name: String?): Contact {
        return setNameField(Field(name))
    }

    // hint:D465F782
    fun unsetName(): Contact {
        return setNameField(Field.unset())
    }

    // hint:47C9A0F6
    fun addName(name: String): Contact {
        if (this.name != null) {
            throw IllegalStateException("Field name of Entity Contact is already set to '${this.name}', refused to add new value '$name'")
        }
        return setName(name)
    }

    ///////////////////////
    //
    // url
    //
    ///////////////////////

    // hint:3A7F9B2E
    val url: String?
        get() = _url.orNull

    // hint:F0C48D71
    fun setUrlField(url: Field): Contact {
        return copy(_url = url)
    }

    // hint:8E56A4D9
    fun updateUrlField(updater: (Field) -> Field): Contact {
        return setUrlField(updater(_url))
    }

    // hint:B1D730FC
    fun updateUrl(updater: (String?) -> String?): Contact {
        return updateUrlField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeUrlField(urlFieldToMerge: Field): Contact {
        return mergeUrl(urlFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeUrl(urlToMerge: String?): Contact {
        return if (urlToMerge == null) {
            this
        } else {
            val oldUrl = _url.orNull
            if (oldUrl == null) {
                setUrlField(Field(urlToMerge))
            } else {
                // hint:2F684DAC
                setUrl(urlToMerge)
            }
        }
    }

    // hint:87B3E19C
    fun setUrl(url: String?): Contact {
        return setUrlField(Field(url))
    }

    // hint:D465F782
    fun unsetUrl(): Contact {
        return setUrlField(Field.unset())
    }

    // hint:47C9A0F6
    fun addUrl(url: String): Contact {
        if (this.url != null) {
            throw IllegalStateException("Field url of Entity Contact is already set to '${this.url}', refused to add new value '$url'")
        }
        return setUrl(url)
    }

    ///////////////////////
    //
    // email
    //
    ///////////////////////

    // hint:3A7F9B2E
    val email: String?
        get() = _email.orNull

    // hint:F0C48D71
    fun setEmailField(email: Field): Contact {
        return copy(_email = email)
    }

    // hint:8E56A4D9
    fun updateEmailField(updater: (Field) -> Field): Contact {
        return setEmailField(updater(_email))
    }

    // hint:B1D730FC
    fun updateEmail(updater: (String?) -> String?): Contact {
        return updateEmailField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeEmailField(emailFieldToMerge: Field): Contact {
        return mergeEmail(emailFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeEmail(emailToMerge: String?): Contact {
        return if (emailToMerge == null) {
            this
        } else {
            val oldEmail = _email.orNull
            if (oldEmail == null) {
                setEmailField(Field(emailToMerge))
            } else {
                // hint:2F684DAC
                setEmail(emailToMerge)
            }
        }
    }

    // hint:87B3E19C
    fun setEmail(email: String?): Contact {
        return setEmailField(Field(email))
    }

    // hint:D465F782
    fun unsetEmail(): Contact {
        return setEmailField(Field.unset())
    }

    // hint:47C9A0F6
    fun addEmail(email: String): Contact {
        if (this.email != null) {
            throw IllegalStateException("Field email of Entity Contact is already set to '${this.email}', refused to add new value '$email'")
        }
        return setEmail(email)
    }

    ///////////////////////
    //
    // extensions
    //
    ///////////////////////

    // hint:3A7F9B2E
    val extensions: Map
        get() = _extensions.orNull ?: emptyMap()

    // hint:F0C48D71
    fun setExtensionsField(extensions: Field>): Contact {
        return copy(_extensions = extensions)
    }

    // hint:8E56A4D9
    fun updateExtensionsField(updater: (Field>) -> Field>): Contact {
        return setExtensionsField(updater(_extensions))
    }

    // hint:B1D730FC
    fun updateExtensions(updater: (Map) -> Map): Contact {
        return updateExtensionsField { field ->
            field.flatMap { value ->
                Field(updater(value))
            }
        }
    }

    // hint:6542E98A
    fun mergeExtensionsField(extensionsFieldToMerge: Field>): Contact {
        return mergeExtensions(extensionsFieldToMerge.orNull)
    }

    // hint:A8BC6F23
    fun mergeExtensions(extensionsToMerge: Map?): Contact {
        return if (extensionsToMerge == null) {
            this
        } else {
            val oldExtensions = _extensions.orNull
            if (oldExtensions == null) {
                setExtensionsField(Field(extensionsToMerge))
            } else {
                // hint:70A3D8B6
                setExtensions(de.lancom.openapi.tools.mergeMap(oldExtensions, extensionsToMerge))
            }
        }
    }

    // hint:87B3E19C
    fun setExtensions(extensions: Map): Contact {
        return setExtensionsField(Field(extensions))
    }

    // hint:D465F782
    fun unsetExtensions(): Contact {
        return setExtensionsField(Field.unset())
    }

    // hint:5C81D396
    fun addExtensions(extensions: Map): Contact {
        return mergeExtensions(extensions)
    }

    // hint:1A6B37F8
    fun addExtensions(vararg extensions: Pair): Contact {
        return addExtensions(extensions.toMap())
    }

    // hint:9D0E4CA5
    fun addExtension(key: String, value: Extension?): Contact {
        return addExtensions(key to value)
    }

    // hint:B8F25E73
    fun addExtension(pair: Pair): Contact {
        return addExtensions(mapOf(pair))
    }

    // hint:6A81E3FD
    override val entityDescriptor: EntityDescriptor by lazy {
        EntityDescriptor(
            entity = this,
            jsonNode = null,
            map = mapOf(
                "name" to _name,
                "url" to _url,
                "email" to _email,
            ),
            flatMap = listOf(
                _extensions,
            ),
            flatten = listOf(
            ),
        )
    }

    override fun toString(): String {
        return this.toYamlString()
    }

    // hint:A0E5F382
    override fun mergeEntity(other: Entity?): Contact {
        return when (other) {
            null ->
                this

            is Contact ->
                merge(other)

            else ->
                TODO()
        }
    }

    // hint:716BFD54
    fun merge(other: Contact?): Contact {
        if (other == null) return this
        return this
            .mergeNameField(other._name)
            .mergeUrlField(other._url)
            .mergeEmailField(other._email)
            .mergeExtensionsField(other._extensions)
    }

    companion object : Parser {

        class Serializer : EntitySerializer(Contact::class.java, Contact)
        class Deserializer : EntityDeserializer(Contact::class.java, Contact)

        // hint:5F72B6D8
        override fun parseWrapper(wrapper: Wrapper): Contact {
            return de.lancom.openapi.jackson.extensionParser(wrapper, ::parseWrapperWithExtensions)
        }

        // hint:2C0E94A7
        fun parseWrapperWithExtensions(wrapper: Wrapper, extensions: Field>): Contact {
            return Contact(
                _name = wrapper["name"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getString()
                        }
                    }
                },
                _url = wrapper["url"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getString()
                        }
                    }
                },
                _email = wrapper["email"].getNullOrElse {
                    getSingle {
                        getSingle {
                            getString()
                        }
                    }
                },
                _extensions = extensions,
            )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy