internal static EstimateApiModel DeserializeEstimateApiModel(XElement element)
        {
            DateTimeOffset?        creationDate           = default;
            string                 entityString           = default;
            DateTimeOffset?        expirationDate         = default;
            string                 footer                 = default;
            long?                  id                     = default;
            DateTimeOffset?        issueDate              = default;
            DocumentEntityApiModel issuer                 = default;
            DateTimeOffset?        lastUpdateDate         = default;
            string                 notes                  = default;
            string                 number                 = default;
            long?                  numberingFormatId      = default;
            long?                  originalIssuerEntityID = default;
            long?                  originalTargetEntityID = default;
            DateTimeOffset?        presupuestoDate        = default;
            double?                retentionAmount        = default;
            double?                retentionPercentage    = default;
            EstimateApiModelStatus?status                 = default;
            DocumentEntityApiModel target                 = default;
            double?                totalAmount            = default;
            double?                totalReAmount          = default;
            double?                totalTaxableAmount     = default;
            double?                totalVatAmount         = default;
            EstimateApiModelType?  type                   = default;
            IReadOnlyList <EstimateLineApiModel> lines    = default;

            if (element.Element("creationDate") is XElement creationDateElement)
            {
                creationDate = creationDateElement.GetDateTimeOffsetValue("O");
            }
            if (element.Element("entityString") is XElement entityStringElement)
            {
                entityString = (string)entityStringElement;
            }
            if (element.Element("expirationDate") is XElement expirationDateElement)
            {
                expirationDate = expirationDateElement.GetDateTimeOffsetValue("O");
            }
            if (element.Element("footer") is XElement footerElement)
            {
                footer = (string)footerElement;
            }
            if (element.Element("id") is XElement idElement)
            {
                id = (long?)idElement;
            }
            if (element.Element("issueDate") is XElement issueDateElement)
            {
                issueDate = issueDateElement.GetDateTimeOffsetValue("O");
            }
            if (element.Element("issuer") is XElement issuerElement)
            {
                issuer = DocumentEntityApiModel.DeserializeDocumentEntityApiModel(issuerElement);
            }
            if (element.Element("lastUpdateDate") is XElement lastUpdateDateElement)
            {
                lastUpdateDate = lastUpdateDateElement.GetDateTimeOffsetValue("O");
            }
            if (element.Element("notes") is XElement notesElement)
            {
                notes = (string)notesElement;
            }
            if (element.Element("number") is XElement numberElement)
            {
                number = (string)numberElement;
            }
            if (element.Element("numberingFormatId") is XElement numberingFormatIdElement)
            {
                numberingFormatId = (long?)numberingFormatIdElement;
            }
            if (element.Element("originalIssuerEntityID") is XElement originalIssuerEntityIDElement)
            {
                originalIssuerEntityID = (long?)originalIssuerEntityIDElement;
            }
            if (element.Element("originalTargetEntityID") is XElement originalTargetEntityIDElement)
            {
                originalTargetEntityID = (long?)originalTargetEntityIDElement;
            }
            if (element.Element("presupuestoDate") is XElement presupuestoDateElement)
            {
                presupuestoDate = presupuestoDateElement.GetDateTimeOffsetValue("O");
            }
            if (element.Element("retentionAmount") is XElement retentionAmountElement)
            {
                retentionAmount = (double?)retentionAmountElement;
            }
            if (element.Element("retentionPercentage") is XElement retentionPercentageElement)
            {
                retentionPercentage = (double?)retentionPercentageElement;
            }
            if (element.Element("status") is XElement statusElement)
            {
                status = new EstimateApiModelStatus(statusElement.Value);
            }
            if (element.Element("target") is XElement targetElement)
            {
                target = DocumentEntityApiModel.DeserializeDocumentEntityApiModel(targetElement);
            }
            if (element.Element("totalAmount") is XElement totalAmountElement)
            {
                totalAmount = (double?)totalAmountElement;
            }
            if (element.Element("totalReAmount") is XElement totalReAmountElement)
            {
                totalReAmount = (double?)totalReAmountElement;
            }
            if (element.Element("totalTaxableAmount") is XElement totalTaxableAmountElement)
            {
                totalTaxableAmount = (double?)totalTaxableAmountElement;
            }
            if (element.Element("totalVatAmount") is XElement totalVatAmountElement)
            {
                totalVatAmount = (double?)totalVatAmountElement;
            }
            if (element.Element("type") is XElement typeElement)
            {
                type = new EstimateApiModelType(typeElement.Value);
            }
            var array = new List <EstimateLineApiModel>();

            foreach (var e in element.Elements("EstimateLineApiModel"))
            {
                array.Add(EstimateLineApiModel.DeserializeEstimateLineApiModel(e));
            }
            lines = array;
            return(new EstimateApiModel(creationDate, entityString, expirationDate, footer, id, issueDate, issuer, lastUpdateDate, lines, notes, number, numberingFormatId, originalIssuerEntityID, originalTargetEntityID, presupuestoDate, retentionAmount, retentionPercentage, status, target, totalAmount, totalReAmount, totalTaxableAmount, totalVatAmount, type));
        }
        internal static EstimateApiModel DeserializeEstimateApiModel(JsonElement element)
        {
            Optional <DateTimeOffset>         creationDate           = default;
            Optional <string>                 entityString           = default;
            Optional <DateTimeOffset>         expirationDate         = default;
            Optional <string>                 footer                 = default;
            Optional <long>                   id                     = default;
            Optional <DateTimeOffset>         issueDate              = default;
            Optional <DocumentEntityApiModel> issuer                 = default;
            Optional <DateTimeOffset>         lastUpdateDate         = default;
            Optional <IReadOnlyList <EstimateLineApiModel> > lines   = default;
            Optional <string>                 notes                  = default;
            Optional <string>                 number                 = default;
            Optional <long>                   numberingFormatId      = default;
            Optional <long>                   originalIssuerEntityID = default;
            Optional <long>                   originalTargetEntityID = default;
            Optional <DateTimeOffset>         presupuestoDate        = default;
            Optional <double>                 retentionAmount        = default;
            Optional <double>                 retentionPercentage    = default;
            Optional <EstimateApiModelStatus> status                 = default;
            Optional <DocumentEntityApiModel> target                 = default;
            Optional <double>                 totalAmount            = default;
            Optional <double>                 totalReAmount          = default;
            Optional <double>                 totalTaxableAmount     = default;
            Optional <double>                 totalVatAmount         = default;
            Optional <EstimateApiModelType>   type                   = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("creationDate"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    creationDate = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("entityString"))
                {
                    entityString = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("expirationDate"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    expirationDate = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("footer"))
                {
                    footer = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    id = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("issueDate"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    issueDate = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("issuer"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    issuer = DocumentEntityApiModel.DeserializeDocumentEntityApiModel(property.Value);
                    continue;
                }
                if (property.NameEquals("lastUpdateDate"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    lastUpdateDate = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("lines"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <EstimateLineApiModel> array = new List <EstimateLineApiModel>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(EstimateLineApiModel.DeserializeEstimateLineApiModel(item));
                    }
                    lines = array;
                    continue;
                }
                if (property.NameEquals("notes"))
                {
                    notes = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("number"))
                {
                    number = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("numberingFormatId"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    numberingFormatId = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("originalIssuerEntityID"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    originalIssuerEntityID = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("originalTargetEntityID"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    originalTargetEntityID = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("presupuestoDate"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    presupuestoDate = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("retentionAmount"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    retentionAmount = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("retentionPercentage"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    retentionPercentage = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("status"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    status = new EstimateApiModelStatus(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("target"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    target = DocumentEntityApiModel.DeserializeDocumentEntityApiModel(property.Value);
                    continue;
                }
                if (property.NameEquals("totalAmount"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    totalAmount = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("totalReAmount"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    totalReAmount = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("totalTaxableAmount"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    totalTaxableAmount = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("totalVatAmount"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    totalVatAmount = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    type = new EstimateApiModelType(property.Value.GetString());
                    continue;
                }
            }
            return(new EstimateApiModel(Optional.ToNullable(creationDate), entityString.Value, Optional.ToNullable(expirationDate), footer.Value, Optional.ToNullable(id), Optional.ToNullable(issueDate), issuer.Value, Optional.ToNullable(lastUpdateDate), Optional.ToList(lines), notes.Value, number.Value, Optional.ToNullable(numberingFormatId), Optional.ToNullable(originalIssuerEntityID), Optional.ToNullable(originalTargetEntityID), Optional.ToNullable(presupuestoDate), Optional.ToNullable(retentionAmount), Optional.ToNullable(retentionPercentage), Optional.ToNullable(status), target.Value, Optional.ToNullable(totalAmount), Optional.ToNullable(totalReAmount), Optional.ToNullable(totalTaxableAmount), Optional.ToNullable(totalVatAmount), Optional.ToNullable(type)));
        }